NAME OpenTelemetry::Instrumentation::Mojo::UserAgent - OpenTelemetry instrumentation for Mojo::UserAgent SYNOPSIS use OpenTelemetry::SDK; use OpenTelemetry::Instrumentation 'Mojo::UserAgent'; # Or pass options to the instrumentation use OpenTelemetry::Instrumentation 'Mojo::UserAgent' => { request_headers => [ ... ], response_headers => [ ... ], }; say Mojo::UserAgent->new->get('https://metacpan.org')->res->body; Or, if you're feeling adventurous: OTEL_TRACES_EXPORTER=console \ perl -Ilib \ -MOpenTelemetry::SDK \ -M'OpenTelemetry::Instrumentation "Mojo::UserAgent"' \ -Mojo -E 'say g("https://metacpan.org/")->body' DESCRIPTION This module can be used to instrument code using Mojo::UserAgent to generate trace data using the OpenTelemetry API. See OpenTelemetry::Instrumentation for more details. The instrumentation provided by this module wraps around "start" in Mojo::UserAgent to automatically generate telemetry data for every request that goes through that code path. Attributes Spans generated by this instrumentation will record the following attributes: http.request.body.size Set to the size of the return value of "body" in Mojo::Message::Request, as reported by length . If this does not return a truthy value, then this attribute will not be set. http.request.header The instrumentation can be configured to store the value of specific request headers under this key (see "request_headers" for more details). When configured to do so, requested headers will be read from the default headers configured with this client, and from the headers set for this specific request. Headers will be stored as they are found, with their names normalised to lowercase and any hyphens (-) converted to underscores (_). The stored values will be coerced to arrayrefs, as per the semantic convention documentation . http.resend_count Set to the number of redirects that were performed when executing this request. Note that although the OpenTelemetry specification requires this to include retries, as Mojo::UserAgent does not do retries by itself, this currently only includes the number of redirects. http.response.body.size Set to the value of the Content-Length header received in the response. If this header was not set, this attribute will not be recorded. http.response.header The instrumentation can be configured to store the value of specific response headers under this key (see "response_headers" for more details). When configured to do so, requested headers will be read from the headers received in the response. Headers will be stored as they are found, with their names normalised to lowercase and any hyphens (-) converted to underscores (_). The stored values will be coerced to arrayrefs, as per the semantic convention documentation . http.response.status_code Set to the status code of the response, as reported by "code" in Mojo::Message::Response. http.request.method Set to the HTTP method of the request, as reported by "method" in Mojo::Message::Request. network.protocol.name Unconditionally set to "http". network.protocol.version Unconditionally set to "1.1". network.transport Unconditionally set to "tcp". server.address Set to the host of the URL, as reported by "host" in URI. server.port Set to the port of the URL, as reported by "port" in URI. url.full Set to the full URL, with the userinfo portion redacted (if it exists) in order to minimise the risk of leaking sensitive information. If present, the userinfo will be rendered as REDACTED:REDACTED. user_agent.original Set to the value returned by "agent" in Mojo::UserAgent. CONFIGURATION request_headers This instrumentation can be configured to store specific request headers with every generated span. In order to do so, set this key to an array reference with the name of the request headers you want as strings. The strings will be matched case-insensitively to the header names, and hyphens and underscores will be treated indistinctly. Otherwise, names will be matched literally. Matching headers will be stored as span attributes under the http.request.header namespace, as described in the semantic convention documentation . response_headers This instrumentation can be configured to store specific response headers with every generated span. In order to do so, set this key to an array reference with the name of the response headers you want as strings. The strings will be matched case-insensitively to the header names, and hyphens and underscores will be treated indistinctly. Otherwise, names will be matched literally. Matching headers will be stored as span attributes under the http.response.header namespace, as described in the semantic convention documentation . SEE ALSO OpenTelemetry OpenTelemetry::Instrumentation OpenTelemetry::Instrumentation::LWP::UserAgent Mojo::Message::Request Mojo::Message::Response Mojo::URL Mojo::UserAgent AUTHORS Javier Arturo Rodriguez A significant part of this code has been ripped off OpenTelemetry::Instrumentation::LWP::UserAgent written by José Joaquín Atria. COPYRIGHT This software is copyright (c) 2026 by Javier Arturo Rodriguez. LICENSE This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.