common.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright The OpenTelemetry Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package otelhttp // import "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
  15. import (
  16. "net/http"
  17. "go.opentelemetry.io/otel/attribute"
  18. "go.opentelemetry.io/otel/trace"
  19. )
  20. // Attribute keys that can be added to a span.
  21. const (
  22. ReadBytesKey = attribute.Key("http.read_bytes") // if anything was read from the request body, the total number of bytes read
  23. ReadErrorKey = attribute.Key("http.read_error") // If an error occurred while reading a request, the string of the error (io.EOF is not recorded)
  24. WroteBytesKey = attribute.Key("http.wrote_bytes") // if anything was written to the response writer, the total number of bytes written
  25. WriteErrorKey = attribute.Key("http.write_error") // if an error occurred while writing a reply, the string of the error (io.EOF is not recorded)
  26. )
  27. // Server HTTP metrics.
  28. const (
  29. // Deprecated: This field is unused.
  30. RequestCount = "http.server.request_count" // Incoming request count total
  31. // Deprecated: Use of this field has been migrated to serverRequestSize. It will be removed in a future version.
  32. RequestContentLength = "http.server.request_content_length" // Incoming request bytes total
  33. // Deprecated: Use of this field has been migrated to serverResponseSize. It will be removed in a future version.
  34. ResponseContentLength = "http.server.response_content_length" // Incoming response bytes total
  35. // Deprecated: Use of this field has been migrated to serverDuration. It will be removed in a future version.
  36. ServerLatency = "http.server.duration" // Incoming end to end duration, milliseconds
  37. serverRequestSize = "http.server.request.size" // Incoming request bytes total
  38. serverResponseSize = "http.server.response.size" // Incoming response bytes total
  39. serverDuration = "http.server.duration" // Incoming end to end duration, milliseconds
  40. )
  41. // Client HTTP metrics.
  42. const (
  43. clientRequestSize = "http.client.request.size" // Outgoing request bytes total
  44. clientResponseSize = "http.client.response.size" // Outgoing response bytes total
  45. clientDuration = "http.client.duration" // Outgoing end to end duration, milliseconds
  46. )
  47. // Filter is a predicate used to determine whether a given http.request should
  48. // be traced. A Filter must return true if the request should be traced.
  49. type Filter func(*http.Request) bool
  50. func newTracer(tp trace.TracerProvider) trace.Tracer {
  51. return tp.Tracer(ScopeName, trace.WithInstrumentationVersion(Version()))
  52. }