semconv

package
v0.72.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package semconv provides OpenTelemetry semantic convention types and functionality.

Package semconv provides OpenTelemetry semantic convention types and functionality.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SplitHostPort

func SplitHostPort(hostport string) (host string, port int)

SplitHostPort splits a network address hostport of the form "host", "host%zone", "[host]", "[host%zone], "host:port", "host%zone:port", "[host]:port", "[host%zone]:port", or ":port" into host or host%zone and port.

An empty host is returned if it is not provided or unparsable. A negative port is returned if it is not provided or unparsable.

Types

type HTTPClient

type HTTPClient struct {
	// contains filtered or unexported fields
}

func NewHTTPClient

func NewHTTPClient(meter metric.Meter) HTTPClient

func (HTTPClient) ErrorType

func (HTTPClient) ErrorType(err error) attribute.KeyValue

ErrorType returns an error.type attribute for the given error. The otelhttp Transport calls the underlying RoundTripper directly, so transport failures arrive as *net.OpError (connection refused, timeout, etc.) rather than *url.Error (which http.Client.Do adds above the Transport layer). This function intentionally does not unwrap further: reporting a single concrete type per failure keeps attribute cardinality bounded, as required by the OTel spec (error.type SHOULD have low cardinality). Callers that need finer-grained error distinctions should inspect the error themselves.

func (HTTPClient) MetricAttributes

func (n HTTPClient) MetricAttributes(req *http.Request, resp *http.Response, statusCode int, additionalAttributes []attribute.KeyValue) []attribute.KeyValue

func (HTTPClient) MetricOptions

func (n HTTPClient) MetricOptions(ma MetricAttributes) MetricOpts

func (HTTPClient) RecordMetrics

func (n HTTPClient) RecordMetrics(ctx context.Context, md MetricData, opts MetricOpts)

func (HTTPClient) RequestTraceAttrs

func (n HTTPClient) RequestTraceAttrs(req *http.Request) []attribute.KeyValue

RequestTraceAttrs returns trace attributes for an HTTP request made by a client.

func (HTTPClient) ResponseTraceAttrs

func (HTTPClient) ResponseTraceAttrs(resp *http.Response) []attribute.KeyValue

ResponseTraceAttrs returns trace attributes for an HTTP response made by a client.

func (HTTPClient) Status

func (HTTPClient) Status(code int) (codes.Code, string)

func (HTTPClient) TraceAttributes

func (HTTPClient) TraceAttributes(host string) []attribute.KeyValue

TraceAttributes returns attributes for httptrace.

type HTTPServer

type HTTPServer struct {
	// contains filtered or unexported fields
}

func NewHTTPServer

func NewHTTPServer(meter metric.Meter) HTTPServer

func (HTTPServer) MetricAttributes

func (n HTTPServer) MetricAttributes(server string, req *http.Request, statusCode int, route string, additionalAttributes []attribute.KeyValue) []attribute.KeyValue

func (HTTPServer) NetworkTransportAttr

func (HTTPServer) NetworkTransportAttr(network string) []attribute.KeyValue

func (HTTPServer) RecordMetrics

func (n HTTPServer) RecordMetrics(ctx context.Context, md ServerMetricData)

func (HTTPServer) RequestTraceAttrs

func (n HTTPServer) RequestTraceAttrs(server string, req *http.Request, opts RequestTraceAttrsOpts) []attribute.KeyValue

RequestTraceAttrs returns trace attributes for an HTTP request received by a server.

The server must be the primary server name if it is known. For example this would be the ServerName directive (https://httpd.apache.org/docs/2.4/mod/core.html#servername) for an Apache server, and the server_name directive (http://nginx.org/en/docs/http/ngx_http_core_module.html#server_name) for an nginx server. More generically, the primary server name would be the host header value that matches the default virtual host of an HTTP server. It should include the host identifier and if a port is used to route to the server that port identifier should be included as an appropriate port suffix.

If the primary server name is not known, server should be an empty string. The req Host will be used to determine the server instead.

func (HTTPServer) ResponseTraceAttrs

func (HTTPServer) ResponseTraceAttrs(resp ResponseTelemetry) []attribute.KeyValue

ResponseTraceAttrs returns trace attributes for telemetry from an HTTP response.

If any of the fields in the ResponseTelemetry are not set the attribute will be omitted.

func (HTTPServer) Route

func (HTTPServer) Route(route string) attribute.KeyValue

Route returns the attribute for the route.

func (HTTPServer) SpanName added in v0.31.0

func (HTTPServer) SpanName(r *http.Request) string

SpanName returns the span name for an HTTP request following the OpenTelemetry HTTP semantic conventions. It returns "{method} {route}" when the request has a pattern, or just "{method}" when no route is available. Non-standard HTTP methods are replaced by "HTTP".

func (HTTPServer) Status

func (HTTPServer) Status(code int) (codes.Code, string)

Status returns a span status code and message for an HTTP status code value returned by a server. Status codes in the 400-499 range are not returned as errors.

type MetricAttributes

type MetricAttributes struct {
	Err error
	Req *http.Request
	// Resp is the client response, if any. It is only consulted by
	// HTTPClient.MetricAttributes to source the negotiated protocol version;
	// server-side metric recording ignores it.
	Resp                 *http.Response
	Route                string
	AdditionalAttributes []attribute.KeyValue
	StatusCode           int
}

type MetricData

type MetricData struct {
	RequestSize     int64
	RequestDuration time.Duration
}

type MetricOpts

type MetricOpts struct {
	// contains filtered or unexported fields
}

func (MetricOpts) AddOptions

func (o MetricOpts) AddOptions() metric.AddOption

func (MetricOpts) MeasurementOption

func (o MetricOpts) MeasurementOption() metric.MeasurementOption

type RequestTraceAttrsOpts

type RequestTraceAttrsOpts struct {
	// If set, this is used as value for the "http.client_ip" attribute.
	HTTPClientIP string
}

type ResponseTelemetry

type ResponseTelemetry struct {
	ReadError  error
	WriteError error
	StatusCode int
	ReadBytes  int64
	WriteBytes int64
}

type ServerMetricData

type ServerMetricData struct {
	ServerName string

	MetricAttributes

	MetricData
	ResponseSize int64
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL