-
Notifications
You must be signed in to change notification settings - Fork 18
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
Make open-telemetry a soft dependency [RHELDST-27627] #196
Merged
amcmahon-rh
merged 2 commits into
release-engineering:main
from
amcmahon-rh:otel-soft-dep
Nov 13, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,2 @@ | ||
pluggy | ||
setuptools | ||
opentelemetry-api | ||
opentelemetry-sdk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,14 +12,23 @@ def func(): | |
import os | ||
import threading | ||
|
||
from opentelemetry import baggage, context, trace | ||
from opentelemetry.baggage.propagation import W3CBaggagePropagator | ||
from opentelemetry.propagate import set_global_textmap | ||
from opentelemetry.sdk.resources import SERVICE_NAME, Resource | ||
from opentelemetry.sdk.trace import TracerProvider | ||
from opentelemetry.sdk.trace.export import BatchSpanProcessor, ConsoleSpanExporter | ||
from opentelemetry.trace import Status, StatusCode | ||
from opentelemetry.trace.propagation.tracecontext import TraceContextTextMapPropagator | ||
try: | ||
from opentelemetry import baggage, context, trace | ||
from opentelemetry.baggage.propagation import W3CBaggagePropagator | ||
from opentelemetry.propagate import set_global_textmap | ||
from opentelemetry.sdk.resources import SERVICE_NAME, Resource | ||
from opentelemetry.sdk.trace import TracerProvider | ||
from opentelemetry.sdk.trace.export import BatchSpanProcessor, ConsoleSpanExporter | ||
from opentelemetry.trace import Status, StatusCode | ||
from opentelemetry.trace.propagation.tracecontext import ( | ||
TraceContextTextMapPropagator, | ||
) | ||
|
||
OPENTELEMETRY_AVAILABLE = True | ||
except ImportError: # pragma: no cover | ||
# Clients aren't expected to have open-telemetry. This flag will be used in | ||
# TracingWrapper to provide pass through functions. | ||
OPENTELEMETRY_AVAILABLE = False | ||
|
||
from pubtools.pluggy import pm | ||
|
||
|
@@ -60,7 +69,16 @@ def _reset(self): | |
# trace.set_tracer_provider global singleton set below can *never* be set up | ||
# more than once in a single process. | ||
|
||
self._enabled_trace = os.getenv("OTEL_TRACING", "").lower() == "true" | ||
self._enabled_trace = ( | ||
os.getenv("OTEL_TRACING", "").lower() == "true" | ||
) and OPENTELEMETRY_AVAILABLE | ||
if ( | ||
os.getenv("OTEL_TRACING", "").lower() == "true" | ||
) and not OPENTELEMETRY_AVAILABLE: | ||
log.debug( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally there should be a test which reaches this line. You could probably |
||
"Tracing is enabled but the open telemetry package is " | ||
"unavailable. Tracing functionality will be disabled." | ||
) | ||
if self._enabled_trace and not self._processor: | ||
log.info("Creating TracingWrapper instance") | ||
exporter = pm.hook.otel_exporter() or ConsoleSpanExporter() | ||
|
@@ -87,7 +105,6 @@ def instrument_func(self, span_name=None, carrier=None, args_to_attr=False): | |
Returns: | ||
The decorated function | ||
""" | ||
tracer = trace.get_tracer(__name__) | ||
|
||
def _instrument_func(func): | ||
@functools.wraps(func) | ||
|
@@ -104,6 +121,7 @@ def wrap(*args, **kwargs): | |
if not self._enabled_trace: | ||
return func(*args, **kwargs) | ||
|
||
tracer = trace.get_tracer(__name__) | ||
trace_ctx = None | ||
token = None | ||
if not context.get_current(): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
pytest | ||
pytest-cov | ||
opentelemetry-api | ||
opentelemetry-sdk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could have a
pragma: no cover
added to pass the coverage check, given that it's probably not worth maintaining two separate test environments with otel present vs missing.