View Source OpentelemetryReq (Opentelemetry Req v1.0.0-rc.1)
Wraps a Req request in an opentelemetry span.
Spans are not created until the request is completed or errored.
Req Path Params
It is strongly encouraged to use the put_path_params
step option.
This allows the span name to include the {target}
portion of the span name described in the
HTTP Span Name guidelines.
Requirements
path_params
option should be set along with a templated path. Only:colon
style is supportedURLAttributes.url_template()
opt-in attribute must be set totrue
Semantic Conventions
All available required and recommended Client HTTP Span semantic conventions are implemented.
Supported opt-in and experimental attributes can be configured using the opt_in_attrs
option.
Options
Opt-in Semantic Convention Attributes
Otel SemConv requires users to explicitly opt in for any attribute with a
requirement level of opt-in
or experimental
. To ensure compatability, always use the
SemConv attribute.
Example:
client =
Req.new()
|> OpentelemetryReq.attach(
opt_in_attrs: [SemConv.URLAttributes.url_template()]
)
client
|> Req.get(
url: "/api/users/:user_id",
path_params: [user_id: user_id]
)
Request and response header attributes are opt-in and can be set with the
request_header_attrs
and response_header_attrs
options. Values should be lower-case.
Trace Header Propagation
By default, trace propagation headers are not injected to requests. There are two options available to propagate trace headers:
- set
propagate_trace_headers
option totrue
when attaching or in the call - manually use
:otel_propagator_text_map.inject/1
Example:
client =
Req.new()
|> OpentelemetryReq.attach(propagate_trace_headers: true)
# or
client =
Req.new()
|> OpentelemetryReq.attach()
Req.get(client, "/", propagate_trace_headers: true)
Span Name Override
The span name can be overridden by setting the span_name
option in the call.
Example:
client =
Req.new()
|> OpentelemetryReq.attach()
Req.get(client, "/", span_name: "custom")
Option Precedence
Options passed in a request take precedence over those passed in
attach/1
.
Summary
Types
Use semantic conventions library to ensure compatability, e.g. HTTPAttributes.http_request_body_size()
Types
@type opt_in_attr() ::
:"http.request.body.size"
| :"http.response.body.size"
| :"network.transport"
| :"url.scheme"
| :"url.template"
| :"user_agent.original"
Use semantic conventions library to ensure compatability, e.g. HTTPAttributes.http_request_body_size()
@type opt_in_attrs() :: [opt_in_attr()]
Functions
@spec attach(Req.Request.t(), options()) :: Req.Request.t()