Skip to content

[BUG]: opentelemetry incorrectly setting up trace_flags #12585

@cvolante54

Description

@cvolante54

Tracer Version(s)

2.21.3

Python Version(s)

3.12.7

Pip Version(s)

24.0

Bug Report

When using google-pubsub opentelemetry feature with ddtrace's opentelemtry provider, I exposed an issue with the current implementation of the OpenTelemetry Span in this library. The following line in google-pubsub

https://github.com/googleapis/python-pubsub/blob/main/google/cloud/pubsub_v1/publisher/_batch/thread.py#L250

span.get_span_context().trace_flags.sampled

Results in an "AttributeError: 'int' object has no attribute 'sampled'" error.

The root cause of the issue is in the following lines:

https://github.com/DataDog/dd-trace-py/blob/main/ddtrace/internal/opentelemetry/span.py#L148-L156

In this case TraceFlags.SAMPLED or TraceFlags.DEFAULT return an integer, not a TraceFlags instance, in order to get a TraceFlags instance you need to call TraceFlags.get_default() or TraceFlags(TraceFlags.SAMPLED), check the source code out here:

https://github.com/open-telemetry/opentelemetry-python/blob/main/opentelemetry-api/src/opentelemetry/trace/span.py#L197-L221

Reproduction Code

No response

Error Logs

No response

Libraries in Use

ddtrace: 2.21.3
opentelemetry: 1.30.0
google-cloud-pubsub: 2.28.0

Operating System

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions