Skip to content
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

Adding a http.route Activity tag for HTTP Triggers when OTel is enabled #10783

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

stebet
Copy link

@stebet stebet commented Jan 31, 2025

Making OTel span names more clear for HTTP triggers and adding the http.route tag to the root Activity

This PR Adds the http.route as discussed in #10560 and makes the span name more clear. Currently there aren't any test specifically for the OTel tags, but I have tested this locally with an existing function app.

This give us a much clearer root span name like this:
image

Earlier the root span name would have just been GET. Now the span has the HttpTrigger.Route added to make it more clear which function is being hit as well as the OTel attribute.

Tagging @RohitRanjanMS since he seems to have been involved with most of the OTel PRs so far and @lmolkova for visibility as well.

Pull request checklist

IMPORTANT: Currently, changes must be backported to the in-proc branch to be included in Core Tools and non-Flex deployments.

  • Backporting to the in-proc branch is not required
  • My changes do not require documentation changes
  • My changes should not be added to the release notes for the next release
    • Otherwise: I've added my notes to release_notes.md
  • My changes do not need to be backported to a previous version
  • My changes do not require diagnostic events changes
  • I have added all required tests (Unit tests, E2E tests)

@stebet stebet requested a review from a team as a code owner January 31, 2025 11:19
if (context.FunctionMetadata?.Trigger?.Raw != null && context.FunctionMetadata.Trigger.Type == "httpTrigger" && context.FunctionMetadata.Trigger.Raw.TryGetValue("route", StringComparison.OrdinalIgnoreCase, out var value))
{
string routeValue = value.ToString();
Activity.Current.DisplayName = $"{Activity.Current.DisplayName} {routeValue}";
Copy link
Member

@lmolkova lmolkova Jan 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is Activity.Current guaranteed here?
Also, wonder if we can rely on its value being http method (something sets it to {METHOD}, but what if it starts to set route too? Or, on older .NET versions it'd likely default to activity name, which would be HttpRequestIn or something similar, but not so friendly.

The tl;dr: do we have method name around? can we format the display name that's guaranteed to comply?

Copy link
Author

@stebet stebet Jan 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking a look @lmolkova :)

The Host that executes this part of the code for httpTriggers is a .NET 8 Web host, so I'm pretty sure if the activity exists and the trigger is an httpTrigger we can count on it being correct. Also, you can see that the activity originates from the Microsoft.AspNetCore OTel library.

I hope @RohitRanjanMS can correct me if I'm wrong.

I'll add a null check on the Activity.Current, I missed that one :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @stebet , I will have a look at this today.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, so what if in the future version Functions would use routing on the worker? Also, if I'm not mistaken, on .NET 8 OTel instrumentations sets ASP.NET Core activity name, but in .NET 9 (or 10, don't remember), it will be the ASP.NET Core itself. Plus some users may enable ASP.NET Core instrumentation and others won't, so it'd be safer to format the whole thing and and not rely on DisplayName matching method.

Copy link
Author

@stebet stebet Feb 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

End users don't have control of this host process except through host.json config (and otel currently is just an on/off setting) AFAIK. It'll always be at the root since it handles the reverse proxying and routing of incoming function requests.

Also the OTEL host telemetry is in preview ATM and I'm just looking to make the existing spans it puts out a little more readable.

@RohitRanjanMS
Copy link
Member

Hi @stebet , let me figure out why http.route is null. If I can fix it, it would be ideal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants