-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add
openetelemetry_info
to user_params
Signed-off-by: Harsh Modi <hmodi@redhat.com>
- Loading branch information
Showing
8 changed files
with
118 additions
and
4 deletions.
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
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
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
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
""" | ||
Copyright (c) 2023 Red Hat, Inc | ||
All rights reserved. | ||
This software may be modified and distributed under the terms | ||
of the BSD license. See the LICENSE file for details. | ||
""" | ||
import logging | ||
import os | ||
from typing import Optional | ||
|
||
from opentelemetry import trace | ||
from opentelemetry.instrumentation.requests import RequestsInstrumentor | ||
from opentelemetry.trace import format_trace_id, format_span_id | ||
from otel_extensions import TelemetryOptions, init_telemetry_provider | ||
|
||
from osbs.constants import OTEL_SERVICE_NAME | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def init_otel(otel_url: Optional[str], traceparent: Optional[str]): | ||
span_exporter = '' | ||
otel_protocol = 'http/protobuf' | ||
if not otel_url: | ||
otel_protocol = 'custom' | ||
span_exporter = '"opentelemetry.sdk.trace.export.ConsoleSpanExporter"' | ||
|
||
if traceparent: | ||
os.environ['TRACEPARENT'] = traceparent | ||
otel_options = TelemetryOptions( | ||
OTEL_SERVICE_NAME=OTEL_SERVICE_NAME, | ||
OTEL_EXPORTER_CUSTOM_SPAN_EXPORTER_TYPE=span_exporter, | ||
OTEL_EXPORTER_OTLP_ENDPOINT=otel_url, | ||
OTEL_EXPORTER_OTLP_PROTOCOL=otel_protocol, | ||
) | ||
init_telemetry_provider(otel_options) | ||
RequestsInstrumentor().instrument() | ||
|
||
|
||
def get_current_traceparent(**kwargs): | ||
tracecontext = trace.get_current_span().get_span_context() | ||
traceparent = (f'00-{format_trace_id(tracecontext.trace_id)}-' | ||
f'{format_span_id(tracecontext.span_id)}-01') | ||
return traceparent |
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