Repository navigation
Fix StartOperation/StopOperation losing or misreporting telemetry fields - #3225
Merged
Rajkumar Rangaraj (rajkumar-rangaraj) merged 8 commits intoOct 8, 2026
Merged
Conversation
OperationHolder.Dispose only mapped DependencyTelemetry, via ActivityShimMapper, which wrote keys the Azure Monitor exporter does not use as intended: - HTTP: http.method (old convention) mixed with url.full/http.response.status_code (new convention), so Data was empty and ResultCode was 0. - SQL/custom types: ResultCode and Data were dropped. - Queue Message: Type became 'queue', Data became the host, and the queue name was exported as a messaging.destination custom dimension. RequestTelemetry fields (Url, ResponseCode, Success) and custom Properties were never applied, and StartOperation added an 'OperationName' tag that was exported as a custom dimension on every operation. - Extract the TrackDependency/TrackRequest activity mapping (Microsoft override attributes, global/custom properties, item-level context) into shared internal helpers and use them from OperationHolder.Dispose for SDK-created activities. - Only export a dependency's operation name when it was explicitly assigned, so a child dependency's own name is not reported as its operation name. - Leave the activity status untouched when Success is not set. - Remove ActivityShimMapper and the OperationName tag. - Add tests that run StartOperation through the Azure Monitor exporter and assert on the exported envelopes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot started reviewing on behalf of
Rajkumar Rangaraj (rajkumar-rangaraj)
September 29, 2026 21:32
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The telemetry-object overload still discards an explicitly pre-populated dependency operation name.
Review effort: Balanced
Findings: 1
Open (1)
What changed in this PR
Aligns StartOperation/StopOperation exports with TrackRequest and TrackDependency.
Changes:
- Reuses shared telemetry-to-activity mapping.
- Removes obsolete shim tags and mapper.
- Adds exporter-level regression tests.
| File | Description |
|---|---|
CHANGELOG.md |
Documents the fix. |
TelemetryClientExtensionTests.cs |
Updates operation-name assertions. |
StartOperationExportTests.cs |
Tests exported envelopes. |
TelemetryClientExtensions.cs |
Enables dispose-time mapping. |
TelemetryClient.cs |
Extracts shared mapping helpers. |
ActivityShimMapper.cs |
Removes obsolete mapping. |
OperationHolder.cs |
Applies telemetry before stopping activities. |
ActivityExtensions.cs |
Removes the unmapped operation-name tag helper. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Review feedback: the previous commit stopped applying dependency fields to caller-owned activities (StartOperation<T>(Activity)), whereas the old ActivityShimMapper applied them, so e.g. Success = false on a wrapped dependency was lost. For caller-owned activities, Dispose now applies only fields the caller explicitly set: the dependency/request override attributes that have a value, the name only if it was changed, and the status when Success has a value. Properties and context are not copied, so the caller's own instrumentation is not overwritten. Also give the export tests unique operation names and add caller-activity tests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot review feedback: StartOperation(T) overwrote a caller-provided Context.Operation.Name with the telemetry's own Name, and OperationHolder then treated that value as the default and never exported it. StartOperation(T) now only defaults Context.Operation.Name when it is empty (matching 2.x), and passes the SDK-generated default to OperationHolder explicitly, so a caller-provided operation name is exported as ai.operation.name. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…cy/TrackRequest Revert the TelemetryClient refactor and the OperationHolder ownership/operation-name tracking. Instead, ActivityShimMapper (called from OperationHolder.Dispose) now: - writes the microsoft.dependency.* / microsoft.request.* override keys that TrackDependency/TrackRequest already use, only for values that are set; - maps RequestTelemetry (Url, Source, ResponseCode) as well as DependencyTelemetry; - copies custom Properties, syncs a renamed Name to the activity display name, and sets the status only when Success has a value. StartOperation no longer adds the unmapped OperationName tag. Item-level Context and operation name are intentionally left out of scope; StartOperation keeps not exporting an operation name, as on main. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Rajkumar Rangaraj (rajkumar-rangaraj)
requested a balanced review from Copilot
September 29, 2026 22:17
Copilot started reviewing on behalf of
Rajkumar Rangaraj (rajkumar-rangaraj)
September 29, 2026 22:18
Copilot review feedback: - StartOperation(Activity) seeds Telemetry.Name and Properties from the activity, so re-applying them on dispose could undo later instrumentation updates. Drop the Name -> DisplayName sync, and only set Properties whose keys are not already on the activity (client GlobalProperties are applied in OnEnd only when absent, so item properties still take precedence). - Assert RequestTelemetry.Source in the export test. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Rajkumar Rangaraj (rajkumar-rangaraj)
requested a balanced review from Copilot
September 29, 2026 22:36
Copilot started reviewing on behalf of
Rajkumar Rangaraj (rajkumar-rangaraj)
September 29, 2026 22:37
Rajkumar Rangaraj (rajkumar-rangaraj)
requested a balanced review from Copilot
October 1, 2026 18:33
Harsimar Kaur (harsimar)
approved these changes
Oct 8, 2026
Harsimar Kaur (harsimar)
approved these changes
Oct 8, 2026
Rajkumar Rangaraj (rajkumar-rangaraj)
enabled auto-merge (squash)
October 8, 2026 23:32
Rajkumar Rangaraj (rajkumar-rangaraj)
deleted the
rajrang/fixStartOperationTags
branch
October 8, 2026 23:36
This was referenced Oct 12, 2026
This was referenced Oct 19, 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.


Fix Issue # (no existing issue; found while investigating #3223).
Changes
StartOperation/StopOperationlost or misreported fields set on the operation telemetry. On dispose,OperationHolderonly mappedDependencyTelemetry, throughActivityShimMapper, which wrote attribute keys the Azure Monitor exporter doesn't use the way it intended.RequestTelemetryfields and customPropertieswere never applied.Exported envelopes from
main, compared withTrackDependency/TrackRequestfor the same values:Track*gives)StartOperationonmain20000Queue Message, datamyqueuequeue, data = the host, target = the full URL, queue name in amessaging.destinationcustom dimension0,Success = falseignoredTelemetry.PropertiesOperationNamecustom dimensionRoot causes:
http.methodtogether with new-convention keys (url.full,http.response.status_code). The exporter picks its old-convention HTTP path based onhttp.methodand then readshttp.url/http.status_code, so it found neither.messaging.destinationinstead ofmessaging.destination.name, and wrote the result code for every dependency type ashttp.response.status_code.StartOperationadded anOperationNametag to the activity. It carried state between operations in 2.x, but nothing reads it in 3.x and the exporter emits it as a custom dimension.Fix (small, contained in the shim):
ActivityShimMappernow writes the samemicrosoft.dependency.*/microsoft.request.*override keys thatTrackDependency/TrackRequestalready use, and only for values that are set.RequestTelemetry(Url,Source,ResponseCode) as well asDependencyTelemetry.Propertieswhose keys aren't already on the activity, so tag values seeded intoPropertiesbyStartOperation(Activity)can't roll back later instrumentation updates. It sets the status only whenSuccesshas a value. A request that never setsSuccesstherefore isn't reported as failed;DependencyTelemetrydefaults toSuccess = true, as before.OperationHolder.Disposecalls the request mapping alongside the existing dependency mapping.StartOperationno longer adds theOperationNametag, andActivityExtensions.SetOperationNameis removed.StartOperation(Activity)keeps the fields the exporter derives from it unless the caller sets them.Out of scope: item-level
Contextand operation name.StartOperationstill doesn't export an operation name, as onmain.Tests
StartOperationExportTests. It runsStartOperationthrough the real exporter with a capturingHttpPipelineTransportand asserts on the exported envelopes. It covers dependency fields for Http, SQL, Queue Message and custom types; theStartOperation(T)overload; request url, source, responseCode and success; properties; theStartOperation(Activity)overload with explicitly set fields, with instrumentation updates made after start, and with an untouched instrumented activity; and that no unmapped keys appear incustomDimensions. Most fail againstmain. The two caller-activity guards (the untouched activity and instrumentation updates after start) are expected to pass onmaintoo.microsoft.sample_rateto the same activity, which throws.TelemetryClientExtensionTeststhat asserted on the removedOperationNameactivity tag.FeatureMetricEmissionHelperTests.ReportsFeaturesSeen. That test also fails on cleanmainin this environment (it expectsunknownand getsvm) and is unrelated.TelemetryClientContextTagsTest.StartOperation_GlobalPropertiesAppliedfails intermittently in full-suite runs with a duplicatemicrosoft.sample_rateexception thrown fromActivitySource.StartActivity, which happens when another test class's tracer provider is active at the same time. It reproduces on puremain(without this PR's tests) and is unrelated.Checklist
For significant contributions please make sure you have completed the following items: