[Tracer] (Event Grid 1/5) Add contract and core behavior - #8911
pablomartinezbernardo wants to merge 1 commit into
Conversation
BenchmarksBenchmark execution time: 2026-10-02 09:27:13 Comparing candidate commit c58e89b in PR branch Found 0 performance improvements and 11 performance regressions! Performance is the same for 61 metrics, 0 unstable metrics, 71 known flaky benchmarks, 53 flaky benchmarks without significant changes.
|
Execution-Time Benchmarks Report ⏱️Execution-time results for samples comparing This PR (8911) and master. ✅ No regressions detected |
a6f6e65 to
4a68967
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4a689671af
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
c67ae6c to
14823fd
Compare
| // extension through the host's shared FunctionAssemblyLoadContext. In that scenario, accessing | ||
| // _uriBuilder through a client duck-type proxy has produced MissingFieldException even though the field | ||
| // exists, so retrieve it from the concrete target type before duck casting the field value. |
There was a problem hiding this comment.
This statement doesn't make any sense to me, nor does the fix 🤔
There was a problem hiding this comment.
This was to work around this bug #9167
It has since been solved and merged to master, so this hack was removed
| // Inject W3C trace context and baggage into CloudEvent ExtensionAttributes. | ||
| // CloudEvent extension attribute names only allow [a-z0-9], so we can't use | ||
| // SpanContextPropagator (which also injects Datadog headers with hyphens). | ||
| // Instead, inject W3C traceparent/tracestate/baggage directly. Pre-populating these keys also prevents | ||
| // the Azure SDK from overwriting with its own Activity-based context. |
There was a problem hiding this comment.
This feels like the wrong behaviour to me - if w3c injection is explicitly not configured, we probably shouldn't start injecting it 🤔 Not saying we should be injecting the others, but we should likely respect the config they provided as best we can? 🤔
There was a problem hiding this comment.
Ah, it looks like you do handle that it's just the AI putting confusing comments in unrelated places as usual 😅
There was a problem hiding this comment.
would be better suited as a method comment rather than here.
There was a problem hiding this comment.
It was already mostly explained as a method comment, so I removed this one
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep it up! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
| IRequestUriBuilder? uriBuilder = null; | ||
| if ((object?)instance is { } target) | ||
| { | ||
| uriBuilder = UriBuilderFieldCache<TTarget>.Field?.GetValue(target)?.DuckCast<IRequestUriBuilder>(); |
There was a problem hiding this comment.
I think this code deserves a comment explaining it, but as Andrew, the one above is not really helping me understand what's going on here.
There was a problem hiding this comment.
This was to work around this bug #9167
It has since been solved and merged to master, so this hack was removed
| where TTarget : IEventGridSenderClient | ||
| { | ||
| var tracer = Tracer.Instance; | ||
| if (!tracer.CurrentTraceSettings.Settings.IsIntegrationEnabled(IntegrationId.AzureEventGrid, defaultValue: false)) |
There was a problem hiding this comment.
I think we could extract this to a method, it'd at least make it less likely that we forget one when switching it to "enabled" on the last PR
There was a problem hiding this comment.
Sounds good, done
| return state; | ||
| } | ||
|
|
||
| private static CallTargetState CreateProducerSpan(Tracer tracer, string? host, int port, IEnumerable? events, object? singleEvent) |
There was a problem hiding this comment.
I have not really dug into this but I feel like we could refactor this to pass the single event as an enumerable of one ? Or maybe there is a perf drawback to doing this ?
Because here there are some special tratments that look wrong, like "ProcessEvent" only for single events and not for multiple ones, except if coming from the other CreateProducerSpan where the injection is done... looks a bit scattered
There was a problem hiding this comment.
Creating an enumarable would be an extra unnecessary allocation.
Otherwise, events from ienumerables can't be processed here, because we would actually initiate enumeration before the SDK does. That's what EventGridEnumerableObserver is fixing. I removed the message count check from ProcessEvent because it is only called for single events, do you think that helps avoid confusion? Or do you maybe have another suggestion given these conditions?
| // Inject W3C trace context and baggage into CloudEvent ExtensionAttributes. | ||
| // CloudEvent extension attribute names only allow [a-z0-9], so we can't use | ||
| // SpanContextPropagator (which also injects Datadog headers with hyphens). | ||
| // Instead, inject W3C traceparent/tracestate/baggage directly. Pre-populating these keys also prevents | ||
| // the Azure SDK from overwriting with its own Activity-based context. |
There was a problem hiding this comment.
would be better suited as a method comment rather than here.
14823fd to
af3da06
Compare
cd06b71 to
edb4c37
Compare
edb4c37 to
c58e89b
Compare

Summary of changes
Adds the contracts and core tracing behavior for Azure Event Grid producer spans.
Reason for change
Provides the shared foundation for Azure Event Grid auto-instrumentation while preserving trace context across published events.
Implementation details
Test coverage
Other details
This is the base PR in a larger Graphite stack.