Skip to content

Using Baggage to propagate attributes from parent Span, Fixes AB#3262849 #2671

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

Open
wants to merge 9 commits into
base: dev
Choose a base branch
from

Conversation

melissaahn
Copy link
Contributor

@melissaahn melissaahn commented Jun 12, 2025

Summary

The passkey telemetry dashboard (and maybe some others) has had issues with latency due to joins being done between the Fido span and the parent span related to acquire token interactive. These join statements by trace id allowed us to associate attributes (such as tenant id) to the Fido span that weren't available in the context of the Fido classes.
In order to directly save the attributes onto the Fido span itself, we can make use of Otel's Baggage, which is meant to help hold data across multiple spans (from parent to children). We can then use an implementation of Otel's TextMapPropagator to serialize the Otel Context and pass it to the AuthenticationActivity as an Extra (similar to what we are doing for spanContext). This Context can then be accessed by the WebViewClient and Fido related classes, where they will retrieve the Baggage.

This PR has the changes to implement this behavior and adds a few static helper classes for TextMapPropagator and Baggage (the baggage class is more relevant for the corresponding Broker PR: https://github.com/AzureAD/ad-accounts-for-android/pull/3119).

While this PR tackles attribute propagation for AuthorizationActivity specifically, Baggage and the helper classes can be used in other areas of the code where propagation is needed as well.

AB#3262849

Copy link

❌ Work item link check failed. Description does not contain AB#{ID}.

Click here to Learn more.

@melissaahn melissaahn requested a review from Copilot June 12, 2025 22:50
Copilot

This comment was marked as outdated.

@github-actions github-actions bot changed the title Using Baggage to propagate attributes from parent Span Using Baggage to propagate attributes from parent Span, Fixes AB#3262849 Jun 12, 2025
@melissaahn melissaahn marked this pull request as ready for review June 13, 2025 01:01
@melissaahn melissaahn requested review from a team as code owners June 13, 2025 01:01
@melissaahn melissaahn requested a review from Copilot June 13, 2025 04:41
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements the propagation of attributes via OpenTelemetry’s Baggage mechanism to eliminate latency issues caused by join operations between spans. Key changes include:

  • Introduction of new helper classes (TextMapPropagatorExtension and BaggageExtension) for injecting and extracting context.
  • Updates to AuthorizationActivity, AuthorizationActivityFactory, and related classes to support OTel context propagation.
  • Adjustments to tests and build configurations to accommodate the new baggage-based context handling.

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
common4j/src/main/com/microsoft/identity/common/java/opentelemetry/TextMapPropagatorExtension.java Implements utilities for OTel context injection and extraction.
common4j/src/main/com/microsoft/identity/common/java/opentelemetry/BaggageExtension.java Adds helper methods for working with baggage in spans.
common4j/src/main/com/microsoft/identity/common/java/opentelemetry/AttributeName.java Introduces additional attribute names for telemetry.
common4j/build.gradle Adds the OTel SDK dependency.
common/src/test/java/com/microsoft/identity/common/internal/fido/AuthFidoChallengeHandlerTest.kt Updates tests with new OTel context parameter.
common/src/main/java/com/microsoft/identity/common/internal/ui/webview/AzureActiveDirectoryWebViewClient.java Refactors span context usage to OTel context.
common/src/main/java/com/microsoft/identity/common/internal/providers/oauth2/AuthorizationActivityFactory.kt Passes OTel context carrier via intent extras.
common/src/main/java/com/microsoft/identity/common/internal/providers/oauth2/AuthorizationActivity.java Extracts and deserializes the OTel context from intent extras.
common/src/main/java/com/microsoft/identity/common/internal/fido/AuthFidoChallengeHandler.kt Utilizes baggage from the OTel context to set span attributes.
common/src/main/java/com/microsoft/identity/common/adal/internal/AuthenticationConstants.java Adds constant for OTEL context carrier.
changelog.txt Documents the baggage-based attribute propagation changes.
Comments suppressed due to low confidence (1)

common/src/main/java/com/microsoft/identity/common/internal/providers/oauth2/AuthorizationActivity.java:77

  • [nitpick] Consider extracting the OTEL context deserialization logic into a dedicated helper method to improve readability and reduce duplication between TIRAMISU and earlier Android versions.
carrier = getIntent().getExtras() != null ? getIntent().getExtras().getSerializable(OTEL_CONTEXT_CARRIER, HashMap.class) : new HashMap<>();

Comment on lines +63 to +68
final TextMapSetter<Map<String, String>> setter = new TextMapSetter<Map<String, String>>() {
@Override
public void set(Map<String, String> carrier, String key, String value) {
if (carrier != null && key != null && value != null) {
carrier.put(key, value);
}
Copy link
Preview

Copilot AI Jun 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider refactoring this anonymous inner class to a lambda expression (if supported by your project’s language version) to improve readability and reduce verbosity.

Suggested change
final TextMapSetter<Map<String, String>> setter = new TextMapSetter<Map<String, String>>() {
@Override
public void set(Map<String, String> carrier, String key, String value) {
if (carrier != null && key != null && value != null) {
carrier.put(key, value);
}
final TextMapSetter<Map<String, String>> setter = (carrier, key, value) -> {
if (carrier != null && key != null && value != null) {
carrier.put(key, value);

Copilot uses AI. Check for mistakes.

@@ -250,6 +250,7 @@ dependencies {
resolvableTestFixturesImplementation "org.robolectric:junit:$rootProject.ext.robolectricVersion"

implementation("io.opentelemetry:opentelemetry-api:$rootProject.ext.openTelemetryVersion")
implementation "io.opentelemetry:opentelemetry-sdk:$rootProject.ext.openTelemetryVersion"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure we can do this for libraries. We have to see what is the since increase with adding this here. OneAuth consumes common so we have to be careful. Other 3p apps using MSAL Android could face it too.

Let's do a size analysis before proceeding

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants