Add auto detection for application ID from connection string if not set#44644
Merged
rads-1996 merged 15 commits intoAzure:mainfrom Jan 22, 2026
Merged
Add auto detection for application ID from connection string if not set#44644rads-1996 merged 15 commits intoAzure:mainfrom
rads-1996 merged 15 commits intoAzure:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR implements auto-detection of application ID from connection strings when not already set in resource attributes. The change allows the Azure Monitor trace exporter to extract the ApplicationId parameter from connection strings and automatically populate it in the OpenTelemetry resource envelope if not already present.
Changes:
- Added application ID extraction to connection string parser
- Modified trace exporter to parse application ID from connection string and conditionally add to resource envelope
- Added new constant
_APPLICATION_ID_RESOURCE_KEYfor the resource attribute key - Updated tests to verify application ID handling and updated mock expectations
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
_connection_string_parser.py |
Added APPLICATION_ID constant and extraction logic to parse application ID from connection string |
_constants.py |
Added _APPLICATION_ID_RESOURCE_KEY constant for resource attribute key |
export/trace/_exporter.py |
Added logic to parse connection string, extract application ID, and conditionally add to resource envelope |
test_connection_string_parser.py |
Added tests for application ID extraction with and without ApplicationId in connection string |
tests/trace/test_trace.py |
Updated test mocks to include application_id parameter and added connection string with ApplicationId to test |
tests/logs/test_logs.py |
Added application ID to test resource and verified it doesn't leak into log properties; removed debug print statement |
Comments suppressed due to low confidence (1)
sdk/monitor/azure-monitor-opentelemetry-exporter/tests/trace/test_trace.py:1742
- The test should verify that when application_id is provided and NOT already present in resource attributes, it gets added. Currently, this test has "microsoft.applicationId" already in the resource attributes (line 1725), and passes the same "test_app_id" as the second argument. This tests the "don't overwrite" behavior, but there's no test case for when the application_id should be added (i.e., when it's not already in the resource but is provided from the connection string).
def test_get_otel_resource_envelope(self):
exporter = self._exporter
test_resource = resources.Resource(
attributes={
"string_test_key": "string_value",
"int_test_key": -1,
"bool_test_key": False,
"float_test_key": 0.5,
"sequence_test_key": ["a", "b"],
"microsoft.applicationId": "test_app_id",
}
)
envelope = exporter._get_otel_resource_envelope(test_resource, "test_app_id")
metric_name = envelope.name
self.assertEqual(metric_name, "Microsoft.ApplicationInsights.Metric")
instrumentation_key = envelope.instrumentation_key
self.assertEqual(instrumentation_key, exporter._instrumentation_key)
monitor_base = envelope.data
self.assertEqual(monitor_base.base_type, "MetricData")
metrics_data = monitor_base.base_data
resource_attributes = metrics_data.properties
self.assertEqual(resource_attributes, test_resource.attributes)
metrics = metrics_data.metrics
self.assertEqual(len(metrics), 1)
self.assertEqual(metrics[0].name, "_OTELRESOURCE_")
...onitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/export/trace/_exporter.py
Outdated
Show resolved
Hide resolved
...tor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_connection_string_parser.py
Show resolved
Hide resolved
7848597 to
5000421
Compare
sdk/monitor/azure-monitor-opentelemetry-exporter/tests/trace/test_trace.py
Outdated
Show resolved
Hide resolved
JacksonWeber
approved these changes
Jan 14, 2026
hectorhdzg
approved these changes
Jan 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Implements spec update: [(https://github.com/aep-health-and-standards/Telemetry-Collection-Spec/pull/730)]. Adds logic to auto detect application ID from connection string if not already set through resource attributes.
All SDK Contribution checklist:
General Guidelines and Best Practices