Semantic Conventions for HTTP Spans

Status: Stable

This document defines semantic conventions for HTTP client and server Spans. They can be used for http and https schemes and various HTTP versions like 1.1, 2 and SPDY.

Warning Existing HTTP instrumentations that are using v1.20.0 of this document (or prior):

  • SHOULD NOT change the version of the HTTP or networking conventions that they emit until the HTTP semantic conventions are marked stable (HTTP stabilization will include stabilization of a core set of networking conventions which are also used in HTTP instrumentations). Conventions include, but are not limited to, attributes, metric and span names, and unit of measure.
  • SHOULD introduce an environment variable OTEL_SEMCONV_STABILITY_OPT_IN in the existing major version which is a comma-separated list of values. The only values defined so far are:
    • http - emit the new, stable HTTP and networking conventions, and stop emitting the old experimental HTTP and networking conventions that the instrumentation emitted previously.
    • http/dup - emit both the old and the stable HTTP and networking conventions, allowing for a seamless transition.
    • The default behavior (in the absence of one of these values) is to continue emitting whatever version of the old experimental HTTP and networking conventions the instrumentation was emitting previously.
    • Note: http/dup has higher precedence than http in case both values are present
  • SHOULD maintain (security patching at a minimum) the existing major version for at least six months after it starts emitting both sets of conventions.
  • SHOULD drop the environment variable in the next major version.

Name

HTTP spans MUST follow the overall guidelines for span names.

HTTP server span names SHOULD be {method} {http.route} if there is a (low-cardinality) http.route available (see below for the exact definition of the {method} placeholder).

If there is no (low-cardinality) http.route available, HTTP server span names SHOULD be {method}.

HTTP client spans have no http.route attribute since client-side instrumentation is not generally aware of the “route”, and therefore HTTP client span names SHOULD be {method}.

The {method} MUST be {http.request.method} if the method represents the original method known to the instrumentation. In other cases (when {http.request.method} is set to _OTHER), {method} MUST be HTTP.

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.

Status

Span Status MUST be left unset if HTTP status code was in the 1xx, 2xx or 3xx ranges, unless there was another error (e.g., network error receiving the response body; or 3xx codes with max redirects exceeded), in which case status MUST be set to Error.

For HTTP status codes in the 4xx range span status MUST be left unset in case of SpanKind.SERVER and MUST be set to Error in case of SpanKind.CLIENT.

For HTTP status codes in the 5xx range, as well as any other code the client failed to interpret, span status MUST be set to Error.

Don’t set the span status description if the reason can be inferred from http.response.status_code.

HTTP request may fail if it was cancelled or an error occurred preventing the client or server from sending/receiving the request/response fully.

When instrumentation detects such errors it MUST set span status to Error and MUST set the error.type attribute.

Common Attributes

The common attributes listed in this section apply to both HTTP clients and servers in addition to the specific attributes listed in the HTTP client and HTTP server sections below.

AttributeTypeDescriptionExamplesRequirement Level
error.typestringDescribes a class of error the operation ended with. [1]timeout; java.net.UnknownHostException; server_certificate_invalid; 500Conditionally Required: If request has ended with an error.
http.request.methodstringHTTP request method. [2]GET; POST; HEADRequired
http.request.method_originalstringOriginal HTTP method sent by the client in the request line.GeT; ACL; fooConditionally Required: [3]
http.response.header.<key>string[]HTTP response headers, <key> being the normalized HTTP Header name (lowercase), the value being the header values. [4]http.response.header.content-type=["application/json"]; http.response.header.my-custom-header=["abc", "def"]Opt-In
http.response.status_codeintHTTP response status code.200Conditionally Required: If and only if one was received/sent.
network.peer.addressstringPeer address of the network connection - IP address or Unix domain socket name.10.1.2.80; /tmp/my.sockRecommended
network.peer.portintPeer port number of the network connection.65123Recommended: If network.peer.address is set.
network.protocol.namestringOSI application layer or non-OSI equivalent. [5]http; spdyConditionally Required: [6]
network.protocol.versionstringVersion of the protocol specified in network.protocol.name. [7]1.0; 1.1; 2; 3Recommended
network.transportstringOSI transport layer or inter-process communication method. [8]tcp; udpOpt-In

[1]: If the request fails with an error before response status code was sent or received, error.type SHOULD be set to exception type (its fully-qualified class name, if applicable) or a component-specific low cardinality error identifier.

If response status code was sent or received and status indicates an error according to HTTP span status definition, error.type SHOULD be set to the status code number (represented as a string), an exception type (if thrown) or a component-specific error identifier.

The error.type value SHOULD be predictable and SHOULD have low cardinality. Instrumentations SHOULD document the list of errors they report.

The cardinality of error.type within one instrumentation library SHOULD be low, but telemetry consumers that aggregate data from multiple instrumentation libraries and applications should be prepared for error.type to have high cardinality at query time, when no additional filters are applied.

If the request has completed successfully, instrumentations SHOULD NOT set error.type.

[2]: HTTP request method value SHOULD be “known” to the instrumentation. By default, this convention defines “known” methods as the ones listed in RFC9110 and the PATCH method defined in RFC5789.

If the HTTP request method is not known to instrumentation, it MUST set the http.request.method attribute to _OTHER.

If the HTTP instrumentation could end up converting valid HTTP request methods to _OTHER, then it MUST provide a way to override the list of known HTTP methods. If this override is done via environment variable, then the environment variable MUST be named OTEL_INSTRUMENTATION_HTTP_KNOWN_METHODS and support a comma-separated list of case-sensitive known HTTP methods (this list MUST be a full override of the default known method, it is not a list of known methods in addition to the defaults).

HTTP method names are case-sensitive and http.request.method attribute value MUST match a known HTTP method name exactly. Instrumentations for specific web frameworks that consider HTTP methods to be case insensitive, SHOULD populate a canonical equivalent. Tracing instrumentations that do so, MUST also set http.request.method_original to the original value.

[3]: If and only if it’s different than http.request.method.

[4]: Instrumentations SHOULD require an explicit configuration of which headers are to be captured. Including all response headers can be a security risk - explicit configuration helps avoid leaking sensitive information. Users MAY explicitly configure instrumentations to capture them even though it is not recommended. The attribute value MUST consist of either multiple header values as an array of strings or a single-item array containing a possibly comma-concatenated string, depending on the way the HTTP library provides access to headers.

[5]: The value SHOULD be normalized to lowercase.

[6]: If not http and network.protocol.version is set.

[7]: network.protocol.version refers to the version of the protocol used and might be different from the protocol client’s version. If the HTTP client has a version of 0.27.2, but sends HTTP version 1.1, this attribute should be set to 1.1.

[8]: Generally tcp for HTTP/1.0, HTTP/1.1, and HTTP/2. Generally udp for HTTP/3. Other obscure implementations are possible.

The following attributes can be important for making sampling decisions and SHOULD be provided at span creation time (if provided at all):

error.type has the following list of well-known values. If one of them applies, then the respective value MUST be used, otherwise a custom value MAY be used.

ValueDescription
_OTHERA fallback error value to be used when the instrumentation doesn’t define a custom value.

http.request.method has the following list of well-known values. If one of them applies, then the respective value MUST be used, otherwise a custom value MAY be used.

ValueDescription
CONNECTCONNECT method.
DELETEDELETE method.
GETGET method.
HEADHEAD method.
OPTIONSOPTIONS method.
PATCHPATCH method.
POSTPOST method.
PUTPUT method.
TRACETRACE method.
_OTHERAny HTTP method that the instrumentation has no prior knowledge of.

network.transport has the following list of well-known values. If one of them applies, then the respective value MUST be used, otherwise a custom value MAY be used.

ValueDescription
tcpTCP
udpUDP
pipeNamed or anonymous pipe.
unixUnix domain socket

HTTP client

This span type represents an outbound HTTP request. There are two ways this can be achieved in an instrumentation:

  1. Instrumentations SHOULD create an HTTP span for each attempt to send an HTTP request over the wire. In case the request is resent, the resend attempts MUST follow the HTTP resend spec. In this case, instrumentations SHOULD NOT (also) emit a logical encompassing HTTP client span.

  2. If for some reason it is not possible to emit a span for each send attempt (because e.g. the instrumented library does not expose hooks that would allow this), instrumentations MAY create an HTTP span for the top-most operation of the HTTP client. In this case, the url.full MUST be the absolute URL that was originally requested, before any HTTP-redirects that may happen when executing the request.

For an HTTP client span, SpanKind MUST be Client.

AttributeTypeDescriptionExamplesRequirement Level
http.request.header.<key>string[]HTTP request headers, <key> being the normalized HTTP Header name (lowercase), the value being the header values. [1]http.request.header.content-type=["application/json"]; http.request.header.x-forwarded-for=["1.2.3.4", "1.2.3.5"]Opt-In
http.request.resend_countintThe ordinal number of request resending attempt (for any reason, including redirects). [2]3Recommended: if and only if request was retried.
server.addressstringHost identifier of the “URI origin” HTTP request is sent to. [3]example.com; 10.1.2.80; /tmp/my.sockRequired
server.portintPort identifier of the “URI origin” HTTP request is sent to. [4]80; 8080; 443Required
url.fullstringAbsolute URL describing a network resource according to RFC3986 [5]https://www.foo.bar/search?q=OpenTelemetry#SemConv; //localhostRequired
url.schemestringThe URI scheme component identifying the used protocol.http; httpsOpt-In
user_agent.originalstringValue of the HTTP User-Agent header sent by the client.CERN-LineMode/2.15 libwww/2.17b3; Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Mobile/15E148 Safari/604.1Opt-In

[1]: Instrumentations SHOULD require an explicit configuration of which headers are to be captured. Including all request headers can be a security risk - explicit configuration helps avoid leaking sensitive information. The User-Agent header is already captured in the user_agent.original attribute. Users MAY explicitly configure instrumentations to capture them even though it is not recommended. The attribute value MUST consist of either multiple header values as an array of strings or a single-item array containing a possibly comma-concatenated string, depending on the way the HTTP library provides access to headers.

[2]: The resend count SHOULD be updated each time an HTTP request gets resent by the client, regardless of what was the cause of the resending (e.g. redirection, authorization failure, 503 Server Unavailable, network issues, or any other).

[3]: If an HTTP client request is explicitly made to an IP address, e.g. http://x.x.x.x:8080, then server.address SHOULD be the IP address x.x.x.x. A DNS lookup SHOULD NOT be used.

[4]: When observed from the client side, and when communicating through an intermediary, server.port SHOULD represent the server port behind any intermediaries, for example proxies, if it’s available.

[5]: For network calls, URL usually has scheme://host[:port][path][?query][#fragment] format, where the fragment is not transmitted over HTTP, but if it is known, it SHOULD be included nevertheless. url.full MUST NOT contain credentials passed via URL in form of https://username:password@www.example.com/. In such case username and password SHOULD be redacted and attribute’s value SHOULD be https://REDACTED:REDACTED@www.example.com/. url.full SHOULD capture the absolute URL when it is available (or can be reconstructed) and SHOULD NOT be validated or modified except for sanitizing purposes.

The following attributes can be important for making sampling decisions and SHOULD be provided at span creation time (if provided at all):

HTTP client span duration

There are some minimal constraints that SHOULD be honored:

  • HTTP client spans SHOULD start sometime before the first request byte is sent. This may or may not include connection time.
  • HTTP client spans SHOULD end sometime after the HTTP response headers are fully read (or when they fail to be read). This may or may not include reading the response body.

If there is any possibility for application code to not fully read the HTTP response (and for the HTTP client library to then have to clean up the HTTP response asynchronously), the HTTP client span SHOULD NOT be ended in this cleanup phase, and instead SHOULD end at some point after the HTTP response headers are fully read (or fail to be read). This avoids the span being ended asynchronously later on at a time which is no longer directly associated with the application code which made the HTTP request.

Because of the potential for confusion around this, HTTP client library instrumentations SHOULD document their behavior around ending HTTP client spans.

HTTP request retries and redirects

Retries and redirects cause more than one physical HTTP request to be sent. A request is resent when an HTTP client library sends more than one HTTP request to satisfy the same API call. This may happen due to following redirects, authorization challenges, 503 Server Unavailable, network issues, or any other.

Each time an HTTP request is resent, the http.resend_count attribute SHOULD be added to each repeated span and set to the ordinal number of the request resend attempt.

See the examples for more details about:

HTTP server

Read the following section to understand how HTTP server instrumentations are suggested to capture server information.

HTTP server definitions

An HTTP request can be routed to a specific HTTP application via intermediaries such as reverse proxies. HTTP requests sent to the same domain name may be handled by multiple applications depending on the port, path, headers, or other parameters.

For example, different versions of the same web-application can run side-by-side as independent applications behind the reverse proxy which routes request to one or another based on the request path.

Instances of different HTTP server applications may run on the same physical host and share the same IP address, but listen to different TCP/UDP ports. In order to route the request to a specific application, reverse proxies usually modify the HTTP Host header replacing the original value provided by the client with an actual proxied server name. This behavior depends on the reverse proxy configuration. In some cases, the Host header is not used when routing request to a specific application, making it prone to having bogus content.

HTTP server frameworks and their instrumentations have limited knowledge about the HTTP infrastructure and intermediaries that requests go through. In a general case, they can only use HTTP request properties such as request target or headers to populate server.* attributes.

Setting server.address and server.port attributes

In the context of HTTP server, server.address and server.port attributes capture the original host name and port. They are intended, whenever possible, to be the same on the client and server sides.

HTTP server instrumentations SHOULD do the best effort when populating server.address and server.port attributes and SHOULD determine them by using the first of the following that applies:

Note: The Host and :authority headers contain host and port number of the server. The same applies to the host identifier of Forwarded header or the X-Forwarded-Host header. Instrumentations SHOULD populate both server.address and server.port attributes by parsing the value of corresponding header.

Application developers MAY overwrite potentially inaccurate values of server.* attributes using a SpanProcessor and MAY capture private host information using applicable resource attributes.

Simple client/server example

simple-http-server.png

Client/server example with reverse proxy

reverse-proxy-http-server.png

HTTP Server semantic conventions

This span type represents an inbound HTTP request.

For an HTTP server span, SpanKind MUST be Server.

AttributeTypeDescriptionExamplesRequirement Level
client.addressstringClient address - domain name if available without reverse DNS lookup; otherwise, IP address or Unix domain socket name. [1]83.164.160.102Recommended
client.portintThe port of whichever client was captured in client.address. [2]65123Opt-In
http.request.header.<key>string[]HTTP request headers, <key> being the normalized HTTP Header name (lowercase), the value being the header values. [3]http.request.header.content-type=["application/json"]; http.request.header.x-forwarded-for=["1.2.3.4", "1.2.3.5"]Opt-In
http.routestringThe matched route, that is, the path template in the format used by the respective server framework. [4]/users/:userID?; {controller}/{action}/{id?}Conditionally Required: If and only if it’s available
network.local.addressstringLocal socket address. Useful in case of a multi-IP host.10.1.2.80; /tmp/my.sockOpt-In
network.local.portintLocal socket port. Useful in case of a multi-port host.65123Opt-In
server.addressstringName of the local HTTP server that received the request. [5]example.com; 10.1.2.80; /tmp/my.sockRecommended
server.portintPort of the local HTTP server that received the request. [6]80; 8080; 443Conditionally Required: If server.address is set.
url.pathstringThe URI path component/searchRequired
url.querystringThe URI query component [7]q=OpenTelemetryConditionally Required: If and only if one was received/sent.
url.schemestringThe URI scheme component identifying the used protocol. [8]http; httpsRequired
user_agent.originalstringValue of the HTTP User-Agent header sent by the client.CERN-LineMode/2.15 libwww/2.17b3; Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Mobile/15E148 Safari/604.1Recommended

[1]: The IP address of the original client behind all proxies, if known (e.g. from Forwarded#for, X-Forwarded-For, or a similar header). Otherwise, the immediate client peer address.

[2]: When observed from the server side, and when communicating through an intermediary, client.port SHOULD represent the client port behind any intermediaries, for example proxies, if it’s available.

[3]: Instrumentations SHOULD require an explicit configuration of which headers are to be captured. Including all request headers can be a security risk - explicit configuration helps avoid leaking sensitive information. The User-Agent header is already captured in the user_agent.original attribute. Users MAY explicitly configure instrumentations to capture them even though it is not recommended. The attribute value MUST consist of either multiple header values as an array of strings or a single-item array containing a possibly comma-concatenated string, depending on the way the HTTP library provides access to headers.

[4]: MUST NOT be populated when this is not supported by the HTTP server framework as the route attribute should have low-cardinality and the URI path can NOT substitute it. SHOULD include the application root if there is one.

[5]: See Setting server.address and server.port attributes.

[6]: See Setting server.address and server.port attributes.

[7]: Sensitive content provided in query string SHOULD be scrubbed when instrumentations can identify it.

[8]: The scheme of the original client request, if known (e.g. from Forwarded#proto, X-Forwarded-Proto, or a similar header). Otherwise, the scheme of the immediate peer request.

The following attributes can be important for making sampling decisions and SHOULD be provided at span creation time (if provided at all):

http.route MUST be provided at span creation time if and only if it’s already available. If it becomes available after span starts, instrumentation MUST populate it anytime before span ends.

Examples

HTTP client-server example

As an example, if a browser request for https://example.com:8080/webshop/articles/4?s=1&t=2 is invoked from a host with IP 192.0.2.4, we may have the following Span on the client side:

Span name: GET

Attribute nameValue
http.request.method"GET"
network.protocol.version"1.1"
url.full"https://example.com:8080/webshop/articles/4?s=1&t=2"
server.addressexample.com
server.port8080
network.peer.address"192.0.2.5"
network.peer.port8080
http.response.status_code200

The corresponding server Span may look like this:

Span name: GET /webshop/articles/:article_id.

Attribute nameValue
http.request.method"GET"
network.protocol.version"1.1"
url.path"/webshop/articles/4"
url.query"s=1&t=2"
server.address"example.com"
server.port8080
url.scheme"https"
http.route"/webshop/articles/:article_id"
http.response.status_code200
client.address"192.0.2.4"
client.socket.address"192.0.2.5" (the client goes through a proxy)
user_agent.original"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:72.0) Gecko/20100101 Firefox/72.0"

HTTP client retries examples

Example of retries in the presence of a trace started by an inbound request:

request (SERVER, trace=t1, span=s1)
  |
  -- GET / - 500 (CLIENT, trace=t1, span=s2)
  |   |
  |   --- server (SERVER, trace=t1, span=s3)
  |
  -- GET / - 500 (CLIENT, trace=t1, span=s4, http.resend_count=1)
  |   |
  |   --- server (SERVER, trace=t1, span=s5)
  |
  -- GET / - 200 (CLIENT, trace=t1, span=s6, http.resend_count=2)
      |
      --- server (SERVER, trace=t1, span=s7)

Example of retries with no trace started upfront:

GET / - 500 (CLIENT, trace=t1, span=s1)
 |
 --- server (SERVER, trace=t1, span=s2)

GET / - 500 (CLIENT, trace=t2, span=s1, http.resend_count=1)
 |
 --- server (SERVER, trace=t2, span=s2)

GET / - 200 (CLIENT, trace=t3, span=s1, http.resend_count=2)
 |
 --- server (SERVER, trace=t3, span=s1)

HTTP client authorization retry examples

Example of retries in the presence of a trace started by an inbound request:

request (SERVER, trace=t1, span=s1)
  |
  -- GET /hello - 401 (CLIENT, trace=t1, span=s2)
  |   |
  |   --- server (SERVER, trace=t1, span=s3)
  |
  -- GET /hello - 200 (CLIENT, trace=t1, span=s4, http.resend_count=1)
      |
      --- server (SERVER, trace=t1, span=s5)

Example of retries with no trace started upfront:

GET /hello - 401 (CLIENT, trace=t1, span=s1)
 |
 --- server (SERVER, trace=t1, span=s2)

GET /hello - 200 (CLIENT, trace=t2, span=s1, http.resend_count=1)
 |
 --- server (SERVER, trace=t2, span=s2)

HTTP client redirects examples

Example of redirects in the presence of a trace started by an inbound request:

request (SERVER, trace=t1, span=s1)
  |
  -- GET / - 302 (CLIENT, trace=t1, span=s2)
  |   |
  |   --- server (SERVER, trace=t1, span=s3)
  |
  -- GET /hello - 200 (CLIENT, trace=t1, span=s4, http.resend_count=1)
      |
      --- server (SERVER, trace=t1, span=s5)

Example of redirects with no trace started upfront:

GET / - 302 (CLIENT, trace=t1, span=s1)
 |
 --- server (SERVER, trace=t1, span=s2)

GET /hello - 200 (CLIENT, trace=t2, span=s1, http.resend_count=1)
 |
 --- server (SERVER, trace=t2, span=s2)

HTTP client call: DNS error

As an example, if a user requested https://does-not-exist-123.com, we may have the following span on the client side:

Attribute nameValue
http.request.method"GET"
network.protocol.version"1.1"
url.full"https://does-not-exist-123.com"
server.address"does-not-exist-123.com"
error.type"java.net.UnknownHostException"

HTTP client call: Internal Server Error

As an example, if a user requested https://example.com and server returned 500, we may have the following span on the client side:

Attribute nameValue
http.request.method"GET"
network.protocol.version"1.1"
url.full"https://example.com"
server.address"example.com"
http.response.status_code500
error.type"500"

HTTP server call: connection dropped before response body was sent

As an example, if a user sent a POST request with a body to https://example.com:8080/uploads/4, we may see the following span on a server side:

Span name: POST /uploads/:document_id.

Attribute nameValue
http.request.method"GET"
url.path"/uploads/4"
url.scheme"https"
http.route"/uploads/:document_id"
http.response.status_code201
error.typeWebSocketDisconnect