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 create context key to contrib #502

Merged
merged 26 commits into from
Jun 11, 2021

Conversation

euniceek
Copy link
Contributor

Description

This PR makes the corresponding changes from otel-python open-telemetry/opentelemetry-python#1372 in the contrib to implement create_key functionality as noted here.

How Has This Been Tested?

tox was ran to ensure the new and existing unit tests all pass.

@euniceek euniceek marked this pull request as ready for review May 21, 2021 22:26
@euniceek euniceek requested review from a team, aabmass and lzchen and removed request for a team May 21, 2021 22:26
CHANGELOG.md Outdated
@@ -5,7 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased](https:/open-telemetry/opentelemetry-python/compare/v1.2.0-0.21b0...HEAD)

- Added support for CreateKey functionality.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Please include this in the 'Added' section.

from opentelemetry.sdk.trace import Span, SpanProcessor
from opentelemetry.sdk.trace.export import SpanExporter
from opentelemetry.trace import INVALID_TRACE_ID
from opentelemetry.util._time import _time_ns

logger = logging.getLogger(__name__)
EXPORT_KEY = create_key("suppress_instrumentation")
Copy link
Contributor

@lzchen lzchen May 24, 2021

Choose a reason for hiding this comment

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

Suggested change
EXPORT_KEY = create_key("suppress_instrumentation")
_SUPPRESS_INSTRUMENTATION_KEY= create_key("suppress_instrumentation")

Copy link
Contributor

@codeboten codeboten left a comment

Choose a reason for hiding this comment

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

Just wanted to confirm my understanding here, the suppress_instrumentation context key was being utilized previously by the instrumentations to check if somewhere the SDK had set it. But from the looks here, this change updates the code to create separate keys for each instrumentation.

I believe this mean that this change breaks the functionality we currently have where the span process can set the suppress_instrumentation key before export to prevent the exporter from generating spans. https:/open-telemetry/opentelemetry-python/blob/77c9867dcb0f3179c1b395729aae6aec2c3133a0/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py#L89

Can you confirm? If so, we should figure out the right way to move forward to not break this functionality.

@euniceek
Copy link
Contributor Author

euniceek commented May 25, 2021

Just wanted to confirm my understanding here, the suppress_instrumentation context key was being utilized previously by the instrumentations to check if somewhere the SDK had set it. But from the looks here, this change updates the code to create separate keys for each instrumentation.

I believe this mean that this change breaks the functionality we currently have where the span process can set the suppress_instrumentation key before export to prevent the exporter from generating spans. https:/open-telemetry/opentelemetry-python/blob/77c9867dcb0f3179c1b395729aae6aec2c3133a0/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py#L89

Can you confirm? If so, we should figure out the right way to move forward to not break this functionality.

Sorry I didn't know the full context behind the suppress_instrumentation before making the changes. Yes your understanding is correct in that a new key is created for each instrumentation. This was because now with the create_key functionality creates a unique key name, which is now not simply suppress_instrumentation.

What I can do is since in the otel-python PR, I am creating a unique suppress_instrumentation key, I could export this key to each instrumentation that uses it instead of calling create_key each time. (I will also rename this from EXPORT_KEY to _SUPPRESS_INSTRUMENTATION_KEY.)
https:/open-telemetry/opentelemetry-python/pull/1853/files#diff-ccdfba02d42525f2fee85e7369c94b7c4976ec22079248bbddf610cd11435739R41

Let me know if you think this is alright!

@ocelotl
Copy link
Contributor

ocelotl commented May 26, 2021

Just wanted to confirm my understanding here, the suppress_instrumentation context key was being utilized previously by the instrumentations to check if somewhere the SDK had set it. But from the looks here, this change updates the code to create separate keys for each instrumentation.
I believe this mean that this change breaks the functionality we currently have where the span process can set the suppress_instrumentation key before export to prevent the exporter from generating spans. https:/open-telemetry/opentelemetry-python/blob/77c9867dcb0f3179c1b395729aae6aec2c3133a0/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py#L89
Can you confirm? If so, we should figure out the right way to move forward to not break this functionality.

Sorry I didn't know the full context behind the suppress_instrumentation context key before making the changes. Yes your understanding is correct in that a new key is created for each instrumentation. This was because now with the create_key functionality creates a unique key name, which is now not simply suppress_instrumentation.

What I can do is since in the otel-python PR, I am creating a unique suppress_instrumentation key, I could export this key to each instrumentation that uses it instead of calling create_key each time. (I will also rename this from EXPORT_KEY to _SUPPRESS_INSTRUMENTATION_KEY.)
https:/open-telemetry/opentelemetry-python/pull/1853/files#diff-ccdfba02d42525f2fee85e7369c94b7c4976ec22079248bbddf610cd11435739R41

Let me know if you think this is alright!

Yes, this makes sense 👍

@codeboten
Copy link
Contributor

Just wanted to confirm my understanding here, the suppress_instrumentation context key was being utilized previously by the instrumentations to check if somewhere the SDK had set it. But from the looks here, this change updates the code to create separate keys for each instrumentation.
I believe this mean that this change breaks the functionality we currently have where the span process can set the suppress_instrumentation key before export to prevent the exporter from generating spans. https:/open-telemetry/opentelemetry-python/blob/77c9867dcb0f3179c1b395729aae6aec2c3133a0/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py#L89
Can you confirm? If so, we should figure out the right way to move forward to not break this functionality.

Sorry I didn't know the full context behind the suppress_instrumentation before making the changes. Yes your understanding is correct in that a new key is created for each instrumentation. This was because now with the create_key functionality creates a unique key name, which is now not simply suppress_instrumentation.

What I can do is since in the otel-python PR, I am creating a unique suppress_instrumentation key, I could export this key to each instrumentation that uses it instead of calling create_key each time. (I will also rename this from EXPORT_KEY to _SUPPRESS_INSTRUMENTATION_KEY.)
https:/open-telemetry/opentelemetry-python/pull/1853/files#diff-ccdfba02d42525f2fee85e7369c94b7c4976ec22079248bbddf610cd11435739R41

Let me know if you think this is alright!

The problem with exporting the key from the SDK is that the instrumentations will then depend on the SDK, which I don't believe they do today. This should likely be part of the API instead, this was discussed in the specification here: open-telemetry/opentelemetry-specification#530

I'll add this to the agenda to discuss it at Thursday's SIG meeting.

@ocelotl
Copy link
Contributor

ocelotl commented May 26, 2021

Just wanted to confirm my understanding here, the suppress_instrumentation context key was being utilized previously by the instrumentations to check if somewhere the SDK had set it. But from the looks here, this change updates the code to create separate keys for each instrumentation.
I believe this mean that this change breaks the functionality we currently have where the span process can set the suppress_instrumentation key before export to prevent the exporter from generating spans. https:/open-telemetry/opentelemetry-python/blob/77c9867dcb0f3179c1b395729aae6aec2c3133a0/opentelemetry-sdk/src/opentelemetry/sdk/trace/export/__init__.py#L89
Can you confirm? If so, we should figure out the right way to move forward to not break this functionality.

Sorry I didn't know the full context behind the suppress_instrumentation before making the changes. Yes your understanding is correct in that a new key is created for each instrumentation. This was because now with the create_key functionality creates a unique key name, which is now not simply suppress_instrumentation.
What I can do is since in the otel-python PR, I am creating a unique suppress_instrumentation key, I could export this key to each instrumentation that uses it instead of calling create_key each time. (I will also rename this from EXPORT_KEY to _SUPPRESS_INSTRUMENTATION_KEY.)
https:/open-telemetry/opentelemetry-python/pull/1853/files#diff-ccdfba02d42525f2fee85e7369c94b7c4976ec22079248bbddf610cd11435739R41
Let me know if you think this is alright!

The problem with exporting the key from the SDK is that the instrumentations will then depend on the SDK, which I don't believe they do today. This should likely be part of the API instead, this was discussed in the specification here: open-telemetry/opentelemetry-specification#530

I'll add this to the agenda to discuss it at Thursday's SIG meeting.

Hm, yeah, good point, @codeboten. I think this is the PR that added the suppress instrumentation key to the API.

@euniceek euniceek force-pushed the context-key-contrib branch 3 times, most recently from 2d8d41a to f05b9f5 Compare May 31, 2021 06:52
Copy link
Contributor

@codeboten codeboten left a comment

Choose a reason for hiding this comment

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

Nice, looks great!

from opentelemetry.trace import StatusCode

_SUPPRESS_INSTRUMENTATION_KEY = create_key("suppress_instrumentation")
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we leave a comment saying that this is a temporary solution, and we are waiting on a decision to how we are handling supressing instrumentations?

Copy link
Contributor

@ocelotl ocelotl left a comment

Choose a reason for hiding this comment

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

Just please add the FIXME, it makes it easier to find stuff that is to be fixed later.

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.

5 participants