Description
Is your feature request related to a problem? Please describe.
We want embrace features of Application Insights and of them is the section about users. I struggled with finding info that for User Id
to be populated correctly I needed to use SpanAttributes.ENDUSER_ID
from opentelemetry.semconv.trace import SpanAttributes
, because every doc and stackoverflow said "use ai.user.id
" for other languages than python (not much about it for python specifically).
Turns out that azure sdk is translating things during export, which in this case
if SpanAttributes.ENDUSER_ID in span.attributes:
envelope.tags[ContextTagKeys.AI_USER_ID] = span.attributes[SpanAttributes.ENDUSER_ID]
where ContextTagKeys.AI_USER_ID
is actually AI_USER_ID = "ai.user.id"
and everything works just great.
Now I have issue with Session Id
.
I figure that if there is AI_USER_ID, there must be something similar for session. And there is AI_SESSION_ID
in Azure SDK and SESSION_ID = session.id
in opentelemetry.semconv._incubating.attributes.session_attributes
, but I couldn't find a way to add analogical code
if SpanAttributes.SESSION_ID in span.attributes:
envelope.tags[ContextTagKeys.AI_SESSION_ID] = span.attributes[SpanAttributes.SESSION_ID]
and adding get_current_span().set_attribute("ai.session.id", "000001")
does add a filter in transaction search, but everything is added to a single session in the user section of Application Insights.
I would love for Python Community to be able to use those features.
Describe the solution you'd like
Options:
- Integrate
SpanAttributes.SESSION_ID
into SDK as opt-in feature. - Provide a workaround to add tag
ContextTagKeys.AI_SESSION_ID
on envelope. - Add some kind of callback to be called on each envelope, so developers can decide what other tags they want to add to envelopes.
Describe alternatives you've considered
- Subclassing a tracer exporter
- override
_span_events_to_envelopes
Additional context
I do get that SESSION_ID is in experimental as of now, but the opt-in should be enough to address that.