Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
macieyng opened this issue Jan 28, 2025 · 3 comments · May be fixed by #39630
Open
Assignees
Labels
Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. Monitor - Distro Monitor OpenTelemetry Distro needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention Workflow: This issue is responsible by Azure service team.

Comments

@macieyng
Copy link
Contributor

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

@github-actions github-actions bot added customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Jan 28, 2025
@xiangyan99 xiangyan99 added Monitor Monitor, Monitor Ingestion, Monitor Query Service Attention Workflow: This issue is responsible by Azure service team. and removed needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. labels Jan 28, 2025
@github-actions github-actions bot added the needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team label Jan 28, 2025
Copy link

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @gulopesd @Haiying-MSFT @jairmyree @joshfree @KarishmaGhiya @KevinBlasko @kurtzeborn @nisha-bhatia @pvaneck @scottaddie @srnagar @ToddKingMSFT.

@pvaneck pvaneck added Monitor - Distro Monitor OpenTelemetry Distro and removed Monitor Monitor, Monitor Ingestion, Monitor Query labels Jan 29, 2025
@kristapratico kristapratico added the Client This issue points to a problem in the data-plane of the library. label Feb 4, 2025
@lzchen
Copy link
Member

lzchen commented Feb 10, 2025

@macieyng

Thanks for your contribution! As you mentioned above, the semantic conventions for Session_id is still experimental so we are wary of adding any features that relate to potential breaking changes, even if they are behind an opt-in mechanism.

@macieyng
Copy link
Contributor Author

@lzchen ok, got it.

@xiangyan99 @pvaneck @kristapratico @annatisch

BTW I think there is a bug in Application Insights in Users section, because I see that there are linked spans that doesn't contain ai.user.id at all.

In the example below only GET / has ai.user.id set. Maybe there is other way how these are correlated, but it's not obvious.

Image

I understand that it doesn't relate to SDK, but maybe you could forward me to someone from the Application Insights product team or let them know about such issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. Monitor - Distro Monitor OpenTelemetry Distro needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Attention Workflow: This issue is responsible by Azure service team.
Projects
None yet
5 participants