-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Add auto detection for application ID from connection string if not set #44644
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 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
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