mxmrlt commented on issue #42424:
URL: https://github.com/apache/airflow/issues/42424#issuecomment-2373923468
The same is needed for OTEL traces.
Indeed we should be able to use documented OTEL_RESOURCE_ATTRIBUTES
environment variable so that we can for instance set and use
ResourceAttributes.DEPLOYMENT_ENVIRONMENT.
This is mandatory to make it work correctly and consistent when monitoring
(Elastic/Kibana/APM for me) moreover when tracing in distributed environnements.
```python
# airflow/traces/otel_tracer.py
class OtelTrace:
"""
Handle all tracing requirements such as getting the tracer, and starting
a new span.
When OTEL is enabled, the Trace class will be replaced by this class.
"""
def __init__(self, span_exporter: ConsoleSpanExporter |
OTLPSpanExporter, tag_string: str | None = None):
self.span_exporter = span_exporter
self.span_processor = BatchSpanProcessor(self.span_exporter)
self.tag_string = tag_string
self.otel_service = conf.get("traces", "otel_service")
def get_tracer(
self, component: str, trace_id: int | None = None, span_id: int |
None = None
) -> OpenTelemetryTracer | Tracer:
"""Tracer that will use special AirflowOtelIdGenerator to control
producing certain span and trace id."""
resource = Resource(
attributes={
HOST_NAME: get_hostname(),
SERVICE_NAME: self.otel_service
# Every other OTEL_RESOURCE_ATTRIBUTES like
'deployment.environment'
# but also everything available in
opentelemetry/semconv/resource/__init__.py
}
)
if trace_id or span_id:
# in case where trace_id or span_id was given
tracer_provider = TracerProvider(
resource=resource,
id_generator=AirflowOtelIdGenerator(span_id=span_id, trace_id=trace_id)
)
else:
tracer_provider = TracerProvider(resource=resource)
tracer_provider.add_span_processor(self.span_processor)
tracer = tracer_provider.get_tracer(component)
"""
Tracer will produce a single ID value if value is provided. Note
that this is one-time only, so any
subsequent call will produce the normal random ids.
"""
return tracer`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]