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

change(opentelemetry): make span name and attributes follow the standard spec #10393

Merged
merged 2 commits into from
Nov 3, 2023

Conversation

indrekj
Copy link
Contributor

@indrekj indrekj commented Oct 25, 2023

Description

The previous implementation did not follow the spec. I'll list the reasoning below.

Span name:

HTTP server span names SHOULD be {http.method} {http.route} if there
is a (low-cardinality) http.route available. HTTP server span names SHOULD be {http.method} if there is no (low-cardinality) http.route available. HTTP client spans have no http.route attribute since client-side instrumentation is not generally aware of the "route", and therefore HTTP client spans SHOULD use {http.method}. Instrumentation MUST NOT default to using URI path as span name, but MAY provide hooks to allow custom logic to override the default span name.

It's clearly mentioned that the span name MUST NOT use URI path, but the previous implementation did exactly that. Now it uses http.method http.route where the latter is added only when available.

http.status_code, http.scheme, http.target, http.method, and net.host.name are required according to the spec.

http.route is required if and only if it is available.

http.user_agent is recommended.

Motivation

The most important thing for us is the span name. The previous one had unlimited cardinality which would be a very bad idea in production (it can slow down the tracing platform and when using 3rd party services it could create huge bills).

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
    Not relevant.
  • I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)
    There obviously is a change, but I would consider it backward-compatible (or at least very low-risk one). I named this as feat but could also say it's a bug fix to make sure we are aligned with the OTel spec

The previous implementation did not [follow the spec][1]. I'll list
reasoning below.

Span name:

> HTTP server span names SHOULD be {http.method} {http.route} if there
is a (low-cardinality) http.route available. HTTP server span names
SHOULD be {http.method} if there is no (low-cardinality) http.route
available. HTTP client spans have no http.route attribute since
client-side instrumentation is not generally aware of the "route", and
therefore HTTP client spans SHOULD use {http.method}. Instrumentation
MUST NOT default to using URI path as span name, but MAY provide hooks
to allow custom logic to override the default span name.

It's clearly mentioned that the span name MUST NOT use URI path, but the
previous implementation did exactly that. Now it uses `http.method
http.route` where the latter is added only when available.

`http.status_code`, `http.scheme`, `http.target`, `http.method`, and
`net.host.name` are required according to the spec.

`http.route` is required if and only if it is abailable.

`http.user_agent` is recommended.

[1]: https://github.com/open-telemetry/opentelemetry-specification/blob/v1.20.0/specification/trace/semantic_conventions/http.md#http-server
@monkeyDluffy6017
Copy link
Contributor

Thanks for your contribution! we will check this later

@monkeyDluffy6017
Copy link
Contributor

@yangxikun Could you help to check this pr?

@indrekj
Copy link
Contributor Author

indrekj commented Oct 30, 2023

@monkeyDluffy6017 @yangxikun friendly ping 🙇 , one of the last things we would like to get in before we can deploy Apisix to non-test envs.

@monkeyDluffy6017
Copy link
Contributor

@indrekj I will check this in this week

@yangxikun
Copy link
Contributor

Approve, Thanks for the contribution!

@monkeyDluffy6017
Copy link
Contributor

@yangxikun click here if you have checked
image

@monkeyDluffy6017 monkeyDluffy6017 changed the title feat: improve opentelemetry span name and attributes change(opentelemetry): make span name and attributes follow the standard spec Nov 2, 2023
@monkeyDluffy6017 monkeyDluffy6017 merged commit 1c3d064 into apache:master Nov 3, 2023
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants