1// Copyright The OpenTelemetry Authors
2// SPDX-License-Identifier: Apache-2.0
3
4package otelhttp // import "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
5
6import (
7 "net/http"
8
9 "go.opentelemetry.io/otel/attribute"
10 "go.opentelemetry.io/otel/trace"
11)
12
13// Attribute keys that can be added to a span.
14const (
15 ReadBytesKey = attribute.Key("http.read_bytes") // if anything was read from the request body, the total number of bytes read
16 ReadErrorKey = attribute.Key("http.read_error") // If an error occurred while reading a request, the string of the error (io.EOF is not recorded)
17 WroteBytesKey = attribute.Key("http.wrote_bytes") // if anything was written to the response writer, the total number of bytes written
18 WriteErrorKey = attribute.Key("http.write_error") // if an error occurred while writing a reply, the string of the error (io.EOF is not recorded)
19)
20
21// Client HTTP metrics.
22const (
23 clientRequestSize = "http.client.request.size" // Outgoing request bytes total
24 clientResponseSize = "http.client.response.size" // Outgoing response bytes total
25 clientDuration = "http.client.duration" // Outgoing end to end duration, milliseconds
26)
27
28// Filter is a predicate used to determine whether a given http.request should
29// be traced. A Filter must return true if the request should be traced.
30type Filter func(*http.Request) bool
31
32func newTracer(tp trace.TracerProvider) trace.Tracer {
33 return tp.Tracer(ScopeName, trace.WithInstrumentationVersion(Version()))
34}