1 // Copyright The OpenTelemetry Authors 2 // SPDX-License-Identifier: Apache-2.0 3 4 package otelhttp // import "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp" 5 6 import ( 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. 14 const ( 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 // Server HTTP metrics. 22 const ( 23 serverRequestSize = "http.server.request.size" // Incoming request bytes total 24 serverResponseSize = "http.server.response.size" // Incoming response bytes total 25 serverDuration = "http.server.duration" // Incoming end to end duration, milliseconds 26 ) 27 28 // Client HTTP metrics. 29 const ( 30 clientRequestSize = "http.client.request.size" // Outgoing request bytes total 31 clientResponseSize = "http.client.response.size" // Outgoing response bytes total 32 clientDuration = "http.client.duration" // Outgoing end to end duration, milliseconds 33 ) 34 35 // Filter is a predicate used to determine whether a given http.request should 36 // be traced. A Filter must return true if the request should be traced. 37 type Filter func(*http.Request) bool 38 39 func newTracer(tp trace.TracerProvider) trace.Tracer { 40 return tp.Tracer(ScopeName, trace.WithInstrumentationVersion(Version())) 41 } 42