-
Notifications
You must be signed in to change notification settings - Fork 381
[Extensions.Enrichment] Add exception handling to trace enrichment #4165
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
Merged
martincostello
merged 5 commits into
open-telemetry:main
from
ysolomchenko:Trace-enrichment-callbacks-lack-exception-handling
Apr 21, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8dfd3e9
Add exception handling to trace enrichment actions and processors
ysolomchenko bbdaebf
Changelog
ysolomchenko 9f70d96
Add exception handling and logging for trace enrichment actions and p…
ysolomchenko 65451f8
Update src/OpenTelemetry.Extensions.Enrichment/Internal/TraceEnrichme…
ysolomchenko 06c17e1
Change log level from Error to Warning
ysolomchenko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
54 changes: 54 additions & 0 deletions
54
src/OpenTelemetry.Extensions.Enrichment/Internal/EnrichmentEventSource.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| using System.Diagnostics.Tracing; | ||
| using OpenTelemetry.Internal; | ||
|
|
||
| namespace OpenTelemetry.Extensions.Enrichment; | ||
|
|
||
| [EventSource(Name = "OpenTelemetry-Extensions-Enrichment")] | ||
| internal sealed class EnrichmentEventSource : EventSource | ||
| { | ||
| public static EnrichmentEventSource Log = new(); | ||
|
|
||
| private EnrichmentEventSource() | ||
| { | ||
| } | ||
|
|
||
| [NonEvent] | ||
| public void TraceEnricherException(string operationName, TraceEnricher enricher, Exception ex) | ||
| { | ||
| if (this.IsEnabled(EventLevel.Warning, EventKeywords.All)) | ||
| { | ||
| var enricherType = enricher.GetType(); | ||
| this.TraceEnricherException(operationName, enricherType.FullName ?? enricherType.Name, ex.ToInvariantString()); | ||
| } | ||
| } | ||
|
|
||
| [NonEvent] | ||
| public void TraceEnrichmentActionException(Action<TraceEnrichmentBag> action, Exception ex) | ||
| { | ||
| if (this.IsEnabled(EventLevel.Warning, EventKeywords.All)) | ||
| { | ||
| var method = action.Method; | ||
| var declaringType = method.DeclaringType; | ||
| var actionName = declaringType is null | ||
| ? method.Name | ||
| : $"{declaringType.FullName ?? declaringType.Name}.{method.Name}"; | ||
|
|
||
| this.TraceEnrichmentActionException(actionName, ex.ToInvariantString()); | ||
| } | ||
| } | ||
|
|
||
| [Event(1, Message = "Trace enricher '{0}' threw during '{1}'. Trace processing will continue. Exception: '{2}'.", Level = EventLevel.Warning)] | ||
| public void TraceEnricherException(string enricherType, string operationName, string exception) | ||
| { | ||
| this.WriteEvent(1, enricherType, operationName, exception); | ||
| } | ||
|
|
||
| [Event(2, Message = "Trace enrichment action '{0}' threw. Trace processing will continue. Exception: '{1}'.", Level = EventLevel.Warning)] | ||
| public void TraceEnrichmentActionException(string actionName, string exception) | ||
| { | ||
| this.WriteEvent(2, actionName, exception); | ||
| } | ||
| } |
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
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
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
17 changes: 17 additions & 0 deletions
17
test/OpenTelemetry.Extensions.Enrichment.Tests/EventSourceTests.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| using OpenTelemetry.Tests; | ||
| using Xunit; | ||
|
|
||
| namespace OpenTelemetry.Extensions.Enrichment.Tests; | ||
|
|
||
| public class EventSourceTests | ||
| { | ||
| [Fact] | ||
| public void EventSourceTests_EnrichmentEventSource() | ||
| { | ||
| var eventSourceType = typeof(TraceEnricher).Assembly.GetType("OpenTelemetry.Extensions.Enrichment.EnrichmentEventSource", throwOnError: true)!; | ||
| EventSourceTestHelper.ValidateEventSourceIds(eventSourceType); | ||
| } | ||
| } |
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.