Skip to content

Add Support for SpanAttributes.SESSION_ID in Python Azure SDK for Application Insights Integration #39433

Open
@macieyng

Description

@macieyng

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:

  1. Integrate SpanAttributes.SESSION_ID into SDK as opt-in feature.
  2. Provide a workaround to add tag ContextTagKeys.AI_SESSION_ID on envelope.
  3. 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.

Image
Image
Image

Metadata

Metadata

Assignees

Labels

ClientThis issue points to a problem in the data-plane of the library.Monitor - DistroMonitor OpenTelemetry DistroService AttentionWorkflow: This issue is responsible by Azure service team.customer-reportedIssues that are reported by GitHub users external to the Azure organization.needs-team-attentionWorkflow: This issue needs attention from Azure service team or SDK teamquestionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions