-
Notifications
You must be signed in to change notification settings - Fork 479
Propagate tags from worker #11575
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: dev
Are you sure you want to change the base?
Propagate tags from worker #11575
Conversation
| // Status of the invocation (success/failure/canceled) | ||
| StatusResult result = 3; | ||
|
|
||
| RpcTraceContext trace_context = 5; |
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.
Will remove this when protobuf is released and updated version is pulled into host repo
| return; | ||
| } | ||
|
|
||
| System.Threading.ExecutionContext.Run(context.AsyncExecutionContext, static state => |
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.
Needs to run in correct context to set the correction activity
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 functionality to propagate trace attributes from language workers back to the host, supporting the broader "app capabilities" feature (#11574). Workers can now send trace context information in their InvocationResponse messages, which the host adds to the current Activity for distributed tracing.
Changes:
- Added
RpcTraceContext trace_contextfield to theInvocationResponseprotobuf message to enable workers to send trace attributes back to the host - Implemented
AddWorkerTraceAttributesmethod in GrpcWorkerChannel to extract worker trace attributes and add them to the current Activity using ExecutionContext.Run
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/WebJobs.Script.Grpc/azure-functions-language-worker-protobuf/src/proto/FunctionRpc.proto | Added trace_context field to InvocationResponse message for worker-to-host trace propagation |
| src/WebJobs.Script.Grpc/Channel/GrpcWorkerChannel.cs | Added AddWorkerTraceAttributes method to process worker trace attributes and integrated it into the InvokeResponse flow |
| private void AddWorkerTraceAttributes(InvocationResponse invocationResponse, ScriptInvocationContext context) | ||
| { | ||
| var attributes = invocationResponse.TraceContext?.Attributes; | ||
| if (attributes is null) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| System.Threading.ExecutionContext.Run(context.AsyncExecutionContext, static state => | ||
| { | ||
| var attrs = (IDictionary<string, string>)state; | ||
| foreach (var kvp in attrs) | ||
| { | ||
| Activity.Current?.AddTag(kvp.Key, kvp.Value); | ||
| } | ||
| }, attributes); | ||
| } |
Copilot
AI
Jan 24, 2026
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.
The new AddWorkerTraceAttributes functionality lacks test coverage. Consider adding tests similar to the existing SendInvocationRequest_ValidateTraceContext tests (lines 1349-1407 in GrpcWorkerChannelTests.cs) that verify worker trace attributes are properly added to Activity.Current when an InvocationResponse with trace context is received.
Issue describing the changes in this PR
resolves #11574
Related worker PR: Azure/azure-functions-dotnet-worker#3303
Depends on protobuf PR + release: Azure/azure-functions-language-worker-protobuf#98
Pull request checklist
IMPORTANT: Currently, changes must be backported to the
in-procbranch to be included in Core Tools and non-Flex deployments.in-procbranch is not requiredrelease_notes.mdAdditional Information
Verified that this works e2e and that custom tags appear in app insights in the portal.