Skip to content

Commit

Permalink
add openetelemetry_info to user_params
Browse files Browse the repository at this point in the history
This will be a dictionary containing, `otel_url`
and `traceparent`. There are used in
tekton tasks to initialize opentelementry and
send traces to opentelemetry collector

* MMENG-3834

Signed-off-by: Harsh Modi <[email protected]>
  • Loading branch information
hjmodi committed Sep 14, 2023
1 parent dc0967f commit 6b47126
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
18 changes: 18 additions & 0 deletions osbs/build/user_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from osbs.exceptions import OsbsValidationException
from osbs.utils import (make_name_from_git, utcnow)

from osbs.utils.otel import get_current_traceparent

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -86,6 +87,7 @@ class BuildCommon(BuildParamsBase):
koji_target = BuildParam("koji_target")
koji_task_id = BuildParam("koji_task_id")
platform = BuildParam("platform")
opentelemetry_info = BuildParam("opentelemetry_info")
reactor_config_map = BuildParam("reactor_config_map")
scratch = BuildParam("scratch")
signing_intent = BuildParam("signing_intent")
Expand Down Expand Up @@ -148,6 +150,17 @@ def make_params(cls,
reactor_config = build_conf.get_reactor_config_map_scratch()
else:
reactor_config = build_conf.get_reactor_config_map()
# we are effectively making current span as parent here
# if the traceparent is not updated then child call will
# be linked to the parent of current call
traceparent = get_current_traceparent()
otel_url = build_conf.get_otel_url()
opentelemetry_info = None
if traceparent or otel_url:
opentelemetry_info = {
"traceparent": traceparent,
"otel_url": otel_url,
}
# Update kwargs with arguments explicitly accepted by this method
kwargs.update({
"component": component,
Expand All @@ -162,6 +175,11 @@ def make_params(cls,
"scratch": build_conf.get_scratch(scratch),
})

if opentelemetry_info:
kwargs.update({
"opentelemetry_info": opentelemetry_info
})

# Drop arguments that are:
# - unknown; some callers may pass deprecated params
# - not set (set to None, either explicitly or implicitly)
Expand Down
16 changes: 16 additions & 0 deletions osbs/utils/otel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
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.
"""
from opentelemetry import trace
from opentelemetry.trace import format_trace_id, format_span_id


def get_current_traceparent():
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
5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ requests
requests-kerberos
six
PyYAML
opentelemetry-api==1.19.0
opentelemetry-exporter-otlp==1.19.0
opentelemetry-instrumentation-requests==0.40b0
opentelemetry-sdk==1.19.0
otel-extensions

0 comments on commit 6b47126

Please sign in to comment.