Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for span collection limit via env vars #1377

Conversation

LetzNico
Copy link
Contributor

@LetzNico LetzNico commented Nov 12, 2020

This adds support for the following env variables:

  • OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT (Maximum allowed span attribute count)
  • OTEL_SPAN_EVENT_COUNT_LIMIT (Maximum allowed span event count)
  • OTEL_SPAN_LINK_COUNT_LIMIT (Maximum allowed span link count)

Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Fixes #1364

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update (not sure?)

How Has This Been Tested?

Unit tests added

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated (Needed? If yes, where?)

@LetzNico LetzNico force-pushed the 1364-support-span-collection-limit-via-env-vars branch 3 times, most recently from 90a5f86 to 9def1dc Compare November 15, 2020 23:39
@LetzNico
Copy link
Contributor Author

Exporter builds do not pass because a test asserting to True logs an errors... I'm not sure I get why it happens while related code has not been updated since mid-october 🤷‍♂️

@LetzNico LetzNico marked this pull request as ready for review November 15, 2020 23:46
@LetzNico LetzNico requested review from a team, toumorokoshi and lzchen and removed request for a team November 15, 2020 23:46
@@ -429,8 +427,10 @@ def __init__(
instrumentation_info: InstrumentationInfo = None,
record_exception: bool = True,
set_status_on_exception: bool = True,
attribute_count_limit: int = None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe tracer.start_as_current_span() and tracer.start_span() needs to have these parameters as well, since that is the suggested way to construct spans through our api.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is an interesting question. If we do that it will violate the API.

There isn't actually a requirement to expose this configuration via the span methods: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/sdk.md#limits-on-span-collections.

This configuration could be handled in the constructor of the TracerProvider, which forwards those values to the Span.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or we can limit configuration to be only done through environment variables, similarly to propagators.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's fine, although something I generally am not a huge fan of. My personal taste for programmatic APIs is not a blocker :)

FWIW my preference comes from the desire for linter / syntax checkers to verify that the method I'm calling exists. It's hard to know whether an environment variable is still supported or not programmatically: you just hope there's no backwards incompatible changes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, as a user I would find it difficult to find out what env vars are available. Perhaps more can be discussed here. For now, I am fine with leaving the programmatic part out of this PR.

Copy link
Member

@toumorokoshi toumorokoshi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes! Overall the idea looks good. I think we do need some way to allow the user to manually wire in the values (sdk.TraceProvider would be good), and if possible we only have to query configuration once in the lifetime of the application to change that setting.

@@ -429,8 +427,10 @@ def __init__(
instrumentation_info: InstrumentationInfo = None,
record_exception: bool = True,
set_status_on_exception: bool = True,
attribute_count_limit: int = None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is an interesting question. If we do that it will violate the API.

There isn't actually a requirement to expose this configuration via the span methods: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/sdk.md#limits-on-span-collections.

This configuration could be handled in the constructor of the TracerProvider, which forwards those values to the Span.

@LetzNico LetzNico force-pushed the 1364-support-span-collection-limit-via-env-vars branch from 9def1dc to b7f367e Compare November 21, 2020 23:31
@LetzNico
Copy link
Contributor Author

Hi! Settled down with:

  • Configuration retrieval in the TracerProvider initialization
  • Environment variables as only way to set those limits

Up for review, do not hesitate if this implementaion is not satisfying (yet!)

@lzchen
Copy link
Contributor

lzchen commented Nov 24, 2020

I think from this comment, we only want these configurations to be modified through environment variables, not through the parameters of the constructor.

@LetzNico
Copy link
Contributor Author

I think from this comment, we only want these configurations to be modified through environment variables, not through the parameters of the constructor.

But aren't tracers and spans supposed to only be created through dedicated methods like (get_tracer(), start_as_current_span() and start_span())? I believe that those constructors parameters are only manipulated by the tracer, derived from the tracer provider, which gets those config from env.

If that is not satisfying, do you think an okay approach would be to simply change those three lines to retrieve from env? https://github.com/open-telemetry/opentelemetry-python/blob/master/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py#L52

@lzchen
Copy link
Contributor

lzchen commented Nov 24, 2020

But aren't tracers and spans supposed to only be created through dedicated methods like (get_tracer(), start_as_current_span() and start_span())?

@lzchen
Copy link
Contributor

lzchen commented Nov 24, 2020

But aren't tracers and spans supposed to only be created through dedicated methods like (get_tracer(), start_as_current_span() and start_span())?

You are correct, however adding these as parameters to those functions will break the api definitions as [mentioned above](#1377 (comment). I think the consensus is to not expose these at all to be manually configured through the constructors, but only configured through environment variables similar to [propagators](https://github.com/open-telemetry/opentelemetry-python/blob/master/opentelemetry-api/src/opentelemetry/propagators/__init__.py#L129.

Copy link
Member

@toumorokoshi toumorokoshi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks.

@@ -907,6 +915,16 @@ def __init__(
if shutdown_on_exit:
self._atexit_handler = atexit.register(self.shutdown)

self.span_attribute_count_limit = Configuration().get(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at this point, you've almost done all the work to make this programmatically configurable: just make each of these defaults customizable, or some combination there of.

But not an issue if you choose not to do so.

@LetzNico LetzNico force-pushed the 1364-support-span-collection-limit-via-env-vars branch from b7f367e to 110011f Compare November 29, 2020 17:24
@LetzNico
Copy link
Contributor Author

Hi @lzchen ! Sorry, I have not taken the time to get back to this.

But aren't tracers and spans supposed to only be created through dedicated methods like (get_tracer(), start_as_current_span() and start_span())?

You are correct, however adding these as parameters to those functions will break the api definitions as [mentioned above](#1377 (comment). I think the consensus is to not expose these at all to be manually configured through the constructors, but only configured through environment variables similar to [propagators](https://github.com/open-telemetry/opentelemetry-python/blob/master/opentelemetry-api/src/opentelemetry/propagators/__init__.py#L129.

Understood! I have tried to write something like this, which basically is like replacing doing that if I'm not mistaken:

-MAX_NUM_ATTRIBUTES = 1000
-MAX_NUM_EVENTS = 1000
-MAX_NUM_LINKS = 1000
+SPAN_ATTRIBUTE_COUNT_LIMIT = Configuration().get(
+    "SPAN_ATTRIBUTE_COUNT_LIMIT", 1000
+)
+SPAN_EVENT_COUNT_LIMIT = Configuration().get(
+    "SPAN_EVENT_COUNT_LIMIT", 1000
+)
+SPAN_LINK_COUNT_LIMIT = Configuration().get(
+    "SPAN_LINK_COUNT_LIMIT", 1000
+)

It makes the feature clunky to test, I don't feel comfortable shipping that but maybe I simply did not understand your suggestion 😐.

I believe that a way to implement those limitations in the code without violating the API is to use intermediary classes. That allows us to leverage the TracerProvider, as @toumorokoshi suggested. According to the spec, I understand that this is where this kind of configuration should live:

In implementations of the API, the TracerProvider is expected to be the stateful object that holds any configuration.

I've updated the PR with that, tell me what you think about it. The style does not pass, but I'd really like a feedback before investing more time in either fixing the style or finding a better way to implement the "global" solution

@lzchen
Copy link
Contributor

lzchen commented Nov 30, 2020

@LetzNico
Your original code of:

-MAX_NUM_ATTRIBUTES = 1000
-MAX_NUM_EVENTS = 1000
-MAX_NUM_LINKS = 1000
+SPAN_ATTRIBUTE_COUNT_LIMIT = Configuration().get(
+    "SPAN_ATTRIBUTE_COUNT_LIMIT", 1000
+)
+SPAN_EVENT_COUNT_LIMIT = Configuration().get(
+    "SPAN_EVENT_COUNT_LIMIT", 1000
+)
+SPAN_LINK_COUNT_LIMIT = Configuration().get(
+    "SPAN_LINK_COUNT_LIMIT", 1000
+)

is what I was referring to and is correct.

If you need guidance on how to test this, you can patch the the environment variables and pass in your own values like here.

LetzNico added a commit to LetzNico/opentelemetry-python that referenced this pull request Dec 4, 2020
This adds support for the following env variables:
* OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT (Maximum allowed span attribute count)
* OTEL_SPAN_EVENT_COUNT_LIMIT (Maximum allowed span event count)
* OTEL_SPAN_LINK_COUNT_LIMIT (Maximum allowed span link count)
@LetzNico LetzNico force-pushed the 1364-support-span-collection-limit-via-env-vars branch from 110011f to 894e4a7 Compare December 4, 2020 16:20
LetzNico added a commit to LetzNico/opentelemetry-python that referenced this pull request Dec 4, 2020
This adds support for the following env variables:
* OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT (Maximum allowed span attribute count)
* OTEL_SPAN_EVENT_COUNT_LIMIT (Maximum allowed span event count)
* OTEL_SPAN_LINK_COUNT_LIMIT (Maximum allowed span link count)
@LetzNico LetzNico force-pushed the 1364-support-span-collection-limit-via-env-vars branch from 894e4a7 to 138cb45 Compare December 4, 2020 16:36
This adds support for the following env variables:
* OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT (Maximum allowed span attribute count)
* OTEL_SPAN_EVENT_COUNT_LIMIT (Maximum allowed span event count)
* OTEL_SPAN_LINK_COUNT_LIMIT (Maximum allowed span link count)
@LetzNico LetzNico force-pushed the 1364-support-span-collection-limit-via-env-vars branch from 138cb45 to fd460de Compare December 4, 2020 17:08
@LetzNico LetzNico force-pushed the 1364-support-span-collection-limit-via-env-vars branch from fd460de to 7096de6 Compare December 4, 2020 17:13
Some of its tests set env vars so they can be retrieved in the
Configuration; since some modules initialize it at load-time, it needs
to be reset before and after tests
@LetzNico LetzNico force-pushed the 1364-support-span-collection-limit-via-env-vars branch from d4ef006 to ee66977 Compare December 5, 2020 13:22
@LetzNico
Copy link
Contributor Author

LetzNico commented Dec 5, 2020

I think we're good now @lzchen ! All of this time for... just that, sorry for the time it took :)

@lzchen lzchen merged commit 553bdfc into open-telemetry:master Dec 8, 2020
codeboten pushed a commit to codeboten/opentelemetry-python that referenced this pull request Dec 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support Span Collection limit env variables
3 participants