...

Source file src/go.opentelemetry.io/otel/semconv/v1.5.0/http.go

Documentation: go.opentelemetry.io/otel/semconv/v1.5.0

     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  
    15  package semconv // import "go.opentelemetry.io/otel/semconv/v1.5.0"
    16  
    17  import (
    18  	"net/http"
    19  
    20  	"go.opentelemetry.io/otel/attribute"
    21  	"go.opentelemetry.io/otel/codes"
    22  	"go.opentelemetry.io/otel/semconv/internal"
    23  	"go.opentelemetry.io/otel/trace"
    24  )
    25  
    26  // HTTP scheme attributes.
    27  var (
    28  	HTTPSchemeHTTP  = HTTPSchemeKey.String("http")
    29  	HTTPSchemeHTTPS = HTTPSchemeKey.String("https")
    30  )
    31  
    32  var sc = &internal.SemanticConventions{
    33  	EnduserIDKey:                EnduserIDKey,
    34  	HTTPClientIPKey:             HTTPClientIPKey,
    35  	HTTPFlavorKey:               HTTPFlavorKey,
    36  	HTTPHostKey:                 HTTPHostKey,
    37  	HTTPMethodKey:               HTTPMethodKey,
    38  	HTTPRequestContentLengthKey: HTTPRequestContentLengthKey,
    39  	HTTPRouteKey:                HTTPRouteKey,
    40  	HTTPSchemeHTTP:              HTTPSchemeHTTP,
    41  	HTTPSchemeHTTPS:             HTTPSchemeHTTPS,
    42  	HTTPServerNameKey:           HTTPServerNameKey,
    43  	HTTPStatusCodeKey:           HTTPStatusCodeKey,
    44  	HTTPTargetKey:               HTTPTargetKey,
    45  	HTTPURLKey:                  HTTPURLKey,
    46  	HTTPUserAgentKey:            HTTPUserAgentKey,
    47  	NetHostIPKey:                NetHostIPKey,
    48  	NetHostNameKey:              NetHostNameKey,
    49  	NetHostPortKey:              NetHostPortKey,
    50  	NetPeerIPKey:                NetPeerIPKey,
    51  	NetPeerNameKey:              NetPeerNameKey,
    52  	NetPeerPortKey:              NetPeerPortKey,
    53  	NetTransportIP:              NetTransportIP,
    54  	NetTransportOther:           NetTransportOther,
    55  	NetTransportTCP:             NetTransportTCP,
    56  	NetTransportUDP:             NetTransportUDP,
    57  	NetTransportUnix:            NetTransportUnix,
    58  }
    59  
    60  // NetAttributesFromHTTPRequest generates attributes of the net
    61  // namespace as specified by the OpenTelemetry specification for a
    62  // span.  The network parameter is a string that net.Dial function
    63  // from standard library can understand.
    64  func NetAttributesFromHTTPRequest(network string, request *http.Request) []attribute.KeyValue {
    65  	return sc.NetAttributesFromHTTPRequest(network, request)
    66  }
    67  
    68  // EndUserAttributesFromHTTPRequest generates attributes of the
    69  // enduser namespace as specified by the OpenTelemetry specification
    70  // for a span.
    71  func EndUserAttributesFromHTTPRequest(request *http.Request) []attribute.KeyValue {
    72  	return sc.EndUserAttributesFromHTTPRequest(request)
    73  }
    74  
    75  // HTTPClientAttributesFromHTTPRequest generates attributes of the
    76  // http namespace as specified by the OpenTelemetry specification for
    77  // a span on the client side.
    78  func HTTPClientAttributesFromHTTPRequest(request *http.Request) []attribute.KeyValue {
    79  	return sc.HTTPClientAttributesFromHTTPRequest(request)
    80  }
    81  
    82  // HTTPServerMetricAttributesFromHTTPRequest generates low-cardinality attributes
    83  // to be used with server-side HTTP metrics.
    84  func HTTPServerMetricAttributesFromHTTPRequest(serverName string, request *http.Request) []attribute.KeyValue {
    85  	return sc.HTTPServerMetricAttributesFromHTTPRequest(serverName, request)
    86  }
    87  
    88  // HTTPServerAttributesFromHTTPRequest generates attributes of the
    89  // http namespace as specified by the OpenTelemetry specification for
    90  // a span on the server side. Currently, only basic authentication is
    91  // supported.
    92  func HTTPServerAttributesFromHTTPRequest(serverName, route string, request *http.Request) []attribute.KeyValue {
    93  	return sc.HTTPServerAttributesFromHTTPRequest(serverName, route, request)
    94  }
    95  
    96  // HTTPAttributesFromHTTPStatusCode generates attributes of the http
    97  // namespace as specified by the OpenTelemetry specification for a
    98  // span.
    99  func HTTPAttributesFromHTTPStatusCode(code int) []attribute.KeyValue {
   100  	return sc.HTTPAttributesFromHTTPStatusCode(code)
   101  }
   102  
   103  // SpanStatusFromHTTPStatusCode generates a status code and a message
   104  // as specified by the OpenTelemetry specification for a span.
   105  func SpanStatusFromHTTPStatusCode(code int) (codes.Code, string) {
   106  	return internal.SpanStatusFromHTTPStatusCode(code)
   107  }
   108  
   109  // SpanStatusFromHTTPStatusCodeAndSpanKind generates a status code and a message
   110  // as specified by the OpenTelemetry specification for a span.
   111  // Exclude 4xx for SERVER to set the appropriate status.
   112  func SpanStatusFromHTTPStatusCodeAndSpanKind(code int, spanKind trace.SpanKind) (codes.Code, string) {
   113  	return internal.SpanStatusFromHTTPStatusCodeAndSpanKind(code, spanKind)
   114  }
   115  

View as plain text