Skip to content

Commit

Permalink
[opentelemetry][callback] Take into account review
Browse files Browse the repository at this point in the history
Signed-off-by: Wilfried Roset <wilfriedroset@users.noreply.github.com>
  • Loading branch information
wilfriedroset committed May 6, 2024
1 parent 9f18813 commit 8e8dd8e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
2 changes: 1 addition & 1 deletion changelogs/fragments/8321-fix-opentelemetry-callback.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
minor_changes:
- opentelemetry - add support for HTTP trace_exporter and configures the behavior via ``OTEL_EXPORTER_OTLP_TRACES_PROTOCOL``
- opentelemetry - add support for HTTP trace_exporter and configures the behavior via ``OTEL_EXPORTER_OTLP_TRACES_PROTOCOL`` (https://github.com/ansible-collections/community.general/issues/7888, https://github.com/ansible-collections/community.general/pull/8321).
27 changes: 11 additions & 16 deletions plugins/callback/opentelemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,21 @@
key: disable_attributes_in_logs
version_added: 7.1.0
otel_exporter_otlp_traces_protocol:
default: grpc
type: str
description:
- OTEL_EXPORTER_OTLP_TRACES_PROTOCOL represents the the transport protocol for spans.
- E(OTEL_EXPORTER_OTLP_TRACES_PROTOCOL) represents the the transport protocol for spans.
- See
U(https://opentelemetry-python.readthedocs.io/en/latest/sdk/environment_variables.html#envvar-OTEL_EXPORTER_OTLP_TRACES_PROTOCOL).
default: grpc
choices:
- grpc
- http/protobuf
env:
- name: OTEL_EXPORTER_OTLP_TRACES_PROTOCOL
ini:
- section: callback_opentelemetry
key: otel_exporter_otlp_traces_protocol
version_added: 8.7.0
version_added: 9.0.0
requirements:
- opentelemetry-api (Python library)
- opentelemetry-exporter-otlp (Python library)
Expand Down Expand Up @@ -137,8 +140,8 @@
try:
from opentelemetry import trace
from opentelemetry.trace import SpanKind
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter as grpcOTLPSpanExporter
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter as httpOTLPSpanExporter
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter as GRPCOTLPSpanExporter
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter as HTTPOTLPSpanExporter
from opentelemetry.sdk.resources import SERVICE_NAME, Resource
from opentelemetry.trace.status import Status, StatusCode
from opentelemetry.trace.propagation.tracecontext import TraceContextTextMapPropagator
Expand Down Expand Up @@ -295,9 +298,9 @@ def generate_distributed_traces(self,

processor = None
if otel_exporter_otlp_traces_protocol == 'grpc':
processor = BatchSpanProcessor(grpcOTLPSpanExporter())
processor = BatchSpanProcessor(GRPCOTLPSpanExporter())
else:
processor = BatchSpanProcessor(httpOTLPSpanExporter())
processor = BatchSpanProcessor(HTTPOTLPSpanExporter())

trace.get_tracer_provider().add_span_processor(processor)

Expand Down Expand Up @@ -525,14 +528,6 @@ def set_options(self, task_keys=None, var_options=None, direct=None):
self.traceparent = self.get_option('traceparent')

self.otel_exporter_otlp_traces_protocol = self.get_option('otel_exporter_otlp_traces_protocol')
if not self.otel_exporter_otlp_traces_protocol:
self.otel_exporter_otlp_traces_protocol = 'grpc'
elif self.otel_exporter_otlp_traces_protocol not in ['grpc', 'http/protobuf']:
self.disabled = True
self._display.warning(
"The `otel_exporter_otlp_traces_protocol` option has been set with an unsupported value `{0}`. "
"Disabling the `opentelemetry` callback plugin.".format(self.otel_exporter_otlp_traces_protocol)
)

def v2_playbook_on_start(self, playbook):
self.ansible_playbook = basename(playbook._file_name)
Expand Down Expand Up @@ -623,7 +618,7 @@ def v2_playbook_on_stats(self, stats):
self.traceparent,
self.disable_logs,
self.disable_attributes_in_logs,
self.otel_exporter_otlp_traces_protocol
self.otel_exporter_otlp_traces_protocol,
)

def v2_runner_on_async_failed(self, result, **kwargs):
Expand Down

0 comments on commit 8e8dd8e

Please sign in to comment.