Skip to content

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

Merged
juststillthinking merged 2 commits into
apache:masterfrom
indrekj:opentelemetry-improvements
Nov 3, 2023
Merged

change(opentelemetry): make span name and attributes follow the standard spec#10393
juststillthinking merged 2 commits into
apache:masterfrom
indrekj:opentelemetry-improvements

Conversation

@indrekj

@indrekj indrekj commented Oct 25, 2023

Copy link
Copy Markdown
Contributor

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
@juststillthinking

Copy link
Copy Markdown
Contributor

Thanks for your contribution! we will check this later

@juststillthinking

Copy link
Copy Markdown
Contributor

@yangxikun Could you help to check this pr?

@indrekj

indrekj commented Oct 30, 2023

Copy link
Copy Markdown
Contributor Author

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

@juststillthinking

Copy link
Copy Markdown
Contributor

@indrekj I will check this in this week

@yangxikun

Copy link
Copy Markdown
Contributor

Approve, Thanks for the contribution!

@juststillthinking

Copy link
Copy Markdown
Contributor

@yangxikun click here if you have checked
image

@juststillthinking juststillthinking changed the title feat: improve opentelemetry span name and attributes change(opentelemetry): make span name and attributes follow the standard spec Nov 2, 2023
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.

4 participants