Skip to content

Fixes AB#3549188 add telemetry in the Broker Discovery flow#3040

Closed
siddhijain wants to merge 3 commits into
devfrom
sjain/add-telemetry-to-the-broker-discovery-flow
Closed

Fixes AB#3549188 add telemetry in the Broker Discovery flow#3040
siddhijain wants to merge 3 commits into
devfrom
sjain/add-telemetry-to-the-broker-discovery-flow

Conversation

@siddhijain

@siddhijain siddhijain commented Mar 20, 2026

Copy link
Copy Markdown
Contributor

Fixes AB#3549188 add telemetry in the Broker Discovery flow

@siddhijain siddhijain requested review from a team as code owners March 20, 2026 04:17
Copilot AI review requested due to automatic review settings March 20, 2026 04:17
@github-actions

Copy link
Copy Markdown

✅ Work item link check complete. Description contains link AB#3549188 to an Azure Boards work item.

1 similar comment
@github-actions

Copy link
Copy Markdown

✅ Work item link check complete. Description contains link AB#3549188 to an Azure Boards work item.

@github-actions

Copy link
Copy Markdown

❌ Work item link check failed. Description contains AB#3549188 but the Bot could not link it to an Azure Boards work item.

Click here to learn more.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds new OpenTelemetry attributes and emits them during Broker Discovery and package state checks to improve diagnosability of broker selection behavior.

Changes:

  • Added new AttributeName entries for package install/enabled state and Broker Discovery telemetry.
  • Emitted Broker Discovery telemetry (installed candidate count, reported active brokers, discovery path) in BrokerDiscoveryClient.
  • Emitted package install/enabled state telemetry in PackageHelper.isPackageInstalledAndEnabled(), and added a vNext changelog entry.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
common4j/src/main/com/microsoft/identity/common/java/opentelemetry/AttributeName.java Introduces new OTel attribute keys for package state + broker discovery.
common/src/main/java/com/microsoft/identity/common/internal/broker/PackageHelper.java Records new package install/enabled state attributes on the current span.
common/src/main/java/com/microsoft/identity/common/internal/activebrokerdiscovery/BrokerDiscoveryClient.kt Records new broker discovery attributes (counts, reported active brokers, chosen path).
changelog.txt Adds a vNext entry for the telemetry addition.

Comment on lines +199 to +203
SpanExtension.current().setAttribute(AttributeName.is_installed_by_application_info.name(), isInstalledByApplicationInfo);
SpanExtension.current().setAttribute(AttributeName.is_enabled_by_application_info.name(), isEnabledByApplicationInfo);
SpanExtension.current().setAttribute(AttributeName.is_installed_by_package_info.name(), isInstalledByPackageInfo);
SpanExtension.current().setAttribute(AttributeName.is_enabled_by_enabled_setting.name(), isEnabledByEnabledSetting);

Copilot AI Mar 20, 2026

Copy link

Choose a reason for hiding this comment

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

isPackageInstalledAndEnabled() sets span attributes (is_installed_by_* / is_enabled_by_*) that are not keyed by package name. In call sites that check multiple packages (e.g., Broker Discovery filters multiple candidates), each invocation overwrites the previous values, so the telemetry ends up representing only the last package checked rather than the overall discovery state. Consider emitting these attributes from the caller with an aggregate (counts/summary) or include a bounded identifier so values aren’t overwritten/misleading.

Suggested change
SpanExtension.current().setAttribute(AttributeName.is_installed_by_application_info.name(), isInstalledByApplicationInfo);
SpanExtension.current().setAttribute(AttributeName.is_enabled_by_application_info.name(), isEnabledByApplicationInfo);
SpanExtension.current().setAttribute(AttributeName.is_installed_by_package_info.name(), isInstalledByPackageInfo);
SpanExtension.current().setAttribute(AttributeName.is_enabled_by_enabled_setting.name(), isEnabledByEnabledSetting);

Copilot uses AI. Check for mistakes.
Comment thread changelog.txt
@@ -1,5 +1,6 @@
vNext
----------
- [MINOR] Add telemetry in the Broker Discovery flow

Copilot AI Mar 20, 2026

Copy link

Choose a reason for hiding this comment

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

Changelog vNext entries in this file consistently include the PR number in parentheses (e.g., (#2679)). This new entry is missing the PR reference, which breaks the established vNext format and makes release notes harder to trace. Update it to include (#<PR_NUMBER>).

Suggested change
- [MINOR] Add telemetry in the Broker Discovery flow
- [MINOR] Add telemetry in the Broker Discovery flow (#<PR_NUMBER>)

Copilot uses AI. Check for mistakes.
Comment on lines +669 to +708
//region Package install/enabled state

/**
* Indicates if the package is installed according to ApplicationInfo.
*/
is_installed_by_application_info,

/**
* Indicates if the package is enabled according to ApplicationInfo.
*/
is_enabled_by_application_info,

/**
* Indicates if the package is installed according to PackageInfo.
*/
is_installed_by_package_info,

/**
* Indicates if the package is enabled according to the enabled setting.
*/
is_enabled_by_enabled_setting,

//endregion

//region Broker discovery

/**
* The number of broker candidates that are installed and have valid signatures.
*/
broker_discovery_installed_candidate_count,

/**
* Comma-separated active broker package names returned by each responding candidate.
*/
broker_discovery_reported_active_brokers,

/**
* The discovery path taken: "cache", "ipc", "account_manager", or "account_manager_fallback".
*/
broker_discovery_path,

Copilot AI Mar 20, 2026

Copy link

Choose a reason for hiding this comment

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

This enum’s header comment notes that changes must be mirrored in the Broker repo’s corresponding AttributeName enum. Since this PR adds new attributes, the Broker repo will also need the same additions to keep telemetry keys consistent across repos. Please ensure the Broker-side enum is updated in a coordinated PR.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@copilot open a new pull request to apply changes based on this feedback

…oker/PackageHelper.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

Copilot AI commented Mar 20, 2026

Copy link
Copy Markdown
Contributor

@siddhijain I've opened a new pull request, #3041, to work on those changes. Once the pull request is ready, I'll request review from you.

…tivebrokerdiscovery/BrokerDiscoveryClient.kt

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

const val ERROR_BUNDLE_KEY = "ERROR_BUNDLE_KEY"

const val ACCOUNT_MANAGER = "ACCOUNT_MANAGER"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

brokerdiscoveryclient is on the SDK side (MSAL/OneAuth/WPJ API), we probably don't get telemetry from the former two. is this intentional?

@siddhijain siddhijain Mar 20, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You're right! I will have to move some of these telemetry data points away from the client side. Similar to enabled settings that might get overridden.

Logger.verbose(methodTag, "Unable to read enabled setting for package: " + packageName);
}

SpanExtension.current().setAttribute(AttributeName.is_installed_by_application_info.name(), isInstalledByApplicationInfo);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

is there another info we could use? (e.g. is the app in hibernation, deep sleep, etc)

@siddhijain siddhijain closed this Mar 20, 2026
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.

4 participants