forked from toolshed/abra
build: go 1.24
We were running behind and there were quite some deprecations to update. This was mostly in the upstream copy/pasta package but seems quite minimal.
This commit is contained in:
45
vendor/go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/handler.go
generated
vendored
45
vendor/go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/handler.go
generated
vendored
@ -12,6 +12,7 @@ import (
|
||||
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/internal/request"
|
||||
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/internal/semconv"
|
||||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/propagation"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
@ -21,15 +22,16 @@ type middleware struct {
|
||||
operation string
|
||||
server string
|
||||
|
||||
tracer trace.Tracer
|
||||
propagators propagation.TextMapPropagator
|
||||
spanStartOptions []trace.SpanStartOption
|
||||
readEvent bool
|
||||
writeEvent bool
|
||||
filters []Filter
|
||||
spanNameFormatter func(string, *http.Request) string
|
||||
publicEndpoint bool
|
||||
publicEndpointFn func(*http.Request) bool
|
||||
tracer trace.Tracer
|
||||
propagators propagation.TextMapPropagator
|
||||
spanStartOptions []trace.SpanStartOption
|
||||
readEvent bool
|
||||
writeEvent bool
|
||||
filters []Filter
|
||||
spanNameFormatter func(string, *http.Request) string
|
||||
publicEndpoint bool
|
||||
publicEndpointFn func(*http.Request) bool
|
||||
metricAttributesFn func(*http.Request) []attribute.KeyValue
|
||||
|
||||
semconv semconv.HTTPServer
|
||||
}
|
||||
@ -79,6 +81,7 @@ func (h *middleware) configure(c *config) {
|
||||
h.publicEndpointFn = c.PublicEndpointFn
|
||||
h.server = c.ServerName
|
||||
h.semconv = semconv.NewHTTPServer(c.Meter)
|
||||
h.metricAttributesFn = c.MetricAttributesFn
|
||||
}
|
||||
|
||||
// serveHTTP sets up tracing and calls the given next http.Handler with the span
|
||||
@ -189,14 +192,16 @@ func (h *middleware) serveHTTP(w http.ResponseWriter, r *http.Request, next http
|
||||
// Use floating point division here for higher precision (instead of Millisecond method).
|
||||
elapsedTime := float64(time.Since(requestStartTime)) / float64(time.Millisecond)
|
||||
|
||||
metricAttributes := semconv.MetricAttributes{
|
||||
Req: r,
|
||||
StatusCode: statusCode,
|
||||
AdditionalAttributes: append(labeler.Get(), h.metricAttributesFromRequest(r)...),
|
||||
}
|
||||
|
||||
h.semconv.RecordMetrics(ctx, semconv.ServerMetricData{
|
||||
ServerName: h.server,
|
||||
ResponseSize: bytesWritten,
|
||||
MetricAttributes: semconv.MetricAttributes{
|
||||
Req: r,
|
||||
StatusCode: statusCode,
|
||||
AdditionalAttributes: labeler.Get(),
|
||||
},
|
||||
ServerName: h.server,
|
||||
ResponseSize: bytesWritten,
|
||||
MetricAttributes: metricAttributes,
|
||||
MetricData: semconv.MetricData{
|
||||
RequestSize: bw.BytesRead(),
|
||||
ElapsedTime: elapsedTime,
|
||||
@ -204,6 +209,14 @@ func (h *middleware) serveHTTP(w http.ResponseWriter, r *http.Request, next http
|
||||
})
|
||||
}
|
||||
|
||||
func (h *middleware) metricAttributesFromRequest(r *http.Request) []attribute.KeyValue {
|
||||
var attributeForRequest []attribute.KeyValue
|
||||
if h.metricAttributesFn != nil {
|
||||
attributeForRequest = h.metricAttributesFn(r)
|
||||
}
|
||||
return attributeForRequest
|
||||
}
|
||||
|
||||
// WithRouteTag annotates spans and metrics with the provided route name
|
||||
// with HTTP route attribute.
|
||||
func WithRouteTag(route string, h http.Handler) http.Handler {
|
||||
|
@ -1,3 +1,6 @@
|
||||
// Code created by gotmpl. DO NOT MODIFY.
|
||||
// source: internal/shared/request/body_wrapper.go.tmpl
|
||||
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
|
10
vendor/go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/internal/request/gen.go
generated
vendored
Normal file
10
vendor/go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/internal/request/gen.go
generated
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package request // import "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/internal/request"
|
||||
|
||||
// Generate request package:
|
||||
//go:generate gotmpl --body=../../../../../../internal/shared/request/body_wrapper.go.tmpl "--data={}" --out=body_wrapper.go
|
||||
//go:generate gotmpl --body=../../../../../../internal/shared/request/body_wrapper_test.go.tmpl "--data={}" --out=body_wrapper_test.go
|
||||
//go:generate gotmpl --body=../../../../../../internal/shared/request/resp_writer_wrapper.go.tmpl "--data={}" --out=resp_writer_wrapper.go
|
||||
//go:generate gotmpl --body=../../../../../../internal/shared/request/resp_writer_wrapper_test.go.tmpl "--data={}" --out=resp_writer_wrapper_test.go
|
@ -1,3 +1,6 @@
|
||||
// Code created by gotmpl. DO NOT MODIFY.
|
||||
// source: internal/shared/request/resp_writer_wrapper.go.tmpl
|
||||
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
|
136
vendor/go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/internal/semconv/env.go
generated
vendored
136
vendor/go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/internal/semconv/env.go
generated
vendored
@ -1,3 +1,6 @@
|
||||
// Code created by gotmpl. DO NOT MODIFY.
|
||||
// source: internal/shared/semconv/env.go.tmpl
|
||||
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
@ -16,6 +19,10 @@ import (
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
)
|
||||
|
||||
// OTelSemConvStabilityOptIn is an environment variable.
|
||||
// That can be set to "old" or "http/dup" to opt into the new HTTP semantic conventions.
|
||||
const OTelSemConvStabilityOptIn = "OTEL_SEMCONV_STABILITY_OPT_IN"
|
||||
|
||||
type ResponseTelemetry struct {
|
||||
StatusCode int
|
||||
ReadBytes int64
|
||||
@ -31,6 +38,11 @@ type HTTPServer struct {
|
||||
requestBytesCounter metric.Int64Counter
|
||||
responseBytesCounter metric.Int64Counter
|
||||
serverLatencyMeasure metric.Float64Histogram
|
||||
|
||||
// New metrics
|
||||
requestBodySizeHistogram metric.Int64Histogram
|
||||
responseBodySizeHistogram metric.Int64Histogram
|
||||
requestDurationHistogram metric.Float64Histogram
|
||||
}
|
||||
|
||||
// RequestTraceAttrs returns trace attributes for an HTTP request received by a
|
||||
@ -56,6 +68,15 @@ func (s HTTPServer) RequestTraceAttrs(server string, req *http.Request) []attrib
|
||||
return OldHTTPServer{}.RequestTraceAttrs(server, req)
|
||||
}
|
||||
|
||||
func (s HTTPServer) NetworkTransportAttr(network string) []attribute.KeyValue {
|
||||
if s.duplicate {
|
||||
return append([]attribute.KeyValue{OldHTTPServer{}.NetworkTransportAttr(network)}, CurrentHTTPServer{}.NetworkTransportAttr(network))
|
||||
}
|
||||
return []attribute.KeyValue{
|
||||
OldHTTPServer{}.NetworkTransportAttr(network),
|
||||
}
|
||||
}
|
||||
|
||||
// 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.
|
||||
@ -103,38 +124,56 @@ type MetricData struct {
|
||||
ElapsedTime float64
|
||||
}
|
||||
|
||||
var metricAddOptionPool = &sync.Pool{
|
||||
New: func() interface{} {
|
||||
return &[]metric.AddOption{}
|
||||
},
|
||||
}
|
||||
|
||||
func (s HTTPServer) RecordMetrics(ctx context.Context, md ServerMetricData) {
|
||||
if s.requestBytesCounter == nil || s.responseBytesCounter == nil || s.serverLatencyMeasure == nil {
|
||||
// This will happen if an HTTPServer{} is used instead of NewHTTPServer.
|
||||
return
|
||||
var (
|
||||
metricAddOptionPool = &sync.Pool{
|
||||
New: func() interface{} {
|
||||
return &[]metric.AddOption{}
|
||||
},
|
||||
}
|
||||
|
||||
attributes := OldHTTPServer{}.MetricAttributes(md.ServerName, md.Req, md.StatusCode, md.AdditionalAttributes)
|
||||
o := metric.WithAttributeSet(attribute.NewSet(attributes...))
|
||||
addOpts := metricAddOptionPool.Get().(*[]metric.AddOption)
|
||||
*addOpts = append(*addOpts, o)
|
||||
s.requestBytesCounter.Add(ctx, md.RequestSize, *addOpts...)
|
||||
s.responseBytesCounter.Add(ctx, md.ResponseSize, *addOpts...)
|
||||
s.serverLatencyMeasure.Record(ctx, md.ElapsedTime, o)
|
||||
*addOpts = (*addOpts)[:0]
|
||||
metricAddOptionPool.Put(addOpts)
|
||||
metricRecordOptionPool = &sync.Pool{
|
||||
New: func() interface{} {
|
||||
return &[]metric.RecordOption{}
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
// TODO: Duplicate Metrics
|
||||
func (s HTTPServer) RecordMetrics(ctx context.Context, md ServerMetricData) {
|
||||
if s.requestBytesCounter != nil && s.responseBytesCounter != nil && s.serverLatencyMeasure != nil {
|
||||
attributes := OldHTTPServer{}.MetricAttributes(md.ServerName, md.Req, md.StatusCode, md.AdditionalAttributes)
|
||||
o := metric.WithAttributeSet(attribute.NewSet(attributes...))
|
||||
addOpts := metricAddOptionPool.Get().(*[]metric.AddOption)
|
||||
*addOpts = append(*addOpts, o)
|
||||
s.requestBytesCounter.Add(ctx, md.RequestSize, *addOpts...)
|
||||
s.responseBytesCounter.Add(ctx, md.ResponseSize, *addOpts...)
|
||||
s.serverLatencyMeasure.Record(ctx, md.ElapsedTime, o)
|
||||
*addOpts = (*addOpts)[:0]
|
||||
metricAddOptionPool.Put(addOpts)
|
||||
}
|
||||
|
||||
if s.duplicate && s.requestDurationHistogram != nil && s.requestBodySizeHistogram != nil && s.responseBodySizeHistogram != nil {
|
||||
attributes := CurrentHTTPServer{}.MetricAttributes(md.ServerName, md.Req, md.StatusCode, md.AdditionalAttributes)
|
||||
o := metric.WithAttributeSet(attribute.NewSet(attributes...))
|
||||
recordOpts := metricRecordOptionPool.Get().(*[]metric.RecordOption)
|
||||
*recordOpts = append(*recordOpts, o)
|
||||
s.requestBodySizeHistogram.Record(ctx, md.RequestSize, *recordOpts...)
|
||||
s.responseBodySizeHistogram.Record(ctx, md.ResponseSize, *recordOpts...)
|
||||
s.requestDurationHistogram.Record(ctx, md.ElapsedTime, o)
|
||||
*recordOpts = (*recordOpts)[:0]
|
||||
metricRecordOptionPool.Put(recordOpts)
|
||||
}
|
||||
}
|
||||
|
||||
func NewHTTPServer(meter metric.Meter) HTTPServer {
|
||||
env := strings.ToLower(os.Getenv("OTEL_SEMCONV_STABILITY_OPT_IN"))
|
||||
env := strings.ToLower(os.Getenv(OTelSemConvStabilityOptIn))
|
||||
duplicate := env == "http/dup"
|
||||
server := HTTPServer{
|
||||
duplicate: duplicate,
|
||||
}
|
||||
server.requestBytesCounter, server.responseBytesCounter, server.serverLatencyMeasure = OldHTTPServer{}.createMeasures(meter)
|
||||
if duplicate {
|
||||
server.requestBodySizeHistogram, server.responseBodySizeHistogram, server.requestDurationHistogram = CurrentHTTPServer{}.createMeasures(meter)
|
||||
}
|
||||
return server
|
||||
}
|
||||
|
||||
@ -145,14 +184,23 @@ type HTTPClient struct {
|
||||
requestBytesCounter metric.Int64Counter
|
||||
responseBytesCounter metric.Int64Counter
|
||||
latencyMeasure metric.Float64Histogram
|
||||
|
||||
// new metrics
|
||||
requestBodySize metric.Int64Histogram
|
||||
requestDuration metric.Float64Histogram
|
||||
}
|
||||
|
||||
func NewHTTPClient(meter metric.Meter) HTTPClient {
|
||||
env := strings.ToLower(os.Getenv("OTEL_SEMCONV_STABILITY_OPT_IN"))
|
||||
env := strings.ToLower(os.Getenv(OTelSemConvStabilityOptIn))
|
||||
duplicate := env == "http/dup"
|
||||
client := HTTPClient{
|
||||
duplicate: env == "http/dup",
|
||||
duplicate: duplicate,
|
||||
}
|
||||
client.requestBytesCounter, client.responseBytesCounter, client.latencyMeasure = OldHTTPClient{}.createMeasures(meter)
|
||||
if duplicate {
|
||||
client.requestBodySize, client.requestDuration = CurrentHTTPClient{}.createMeasures(meter)
|
||||
}
|
||||
|
||||
return client
|
||||
}
|
||||
|
||||
@ -204,34 +252,56 @@ func (o MetricOpts) AddOptions() metric.AddOption {
|
||||
return o.addOptions
|
||||
}
|
||||
|
||||
func (c HTTPClient) MetricOptions(ma MetricAttributes) MetricOpts {
|
||||
func (c HTTPClient) MetricOptions(ma MetricAttributes) map[string]MetricOpts {
|
||||
opts := map[string]MetricOpts{}
|
||||
|
||||
attributes := OldHTTPClient{}.MetricAttributes(ma.Req, ma.StatusCode, ma.AdditionalAttributes)
|
||||
// TODO: Duplicate Metrics
|
||||
set := metric.WithAttributeSet(attribute.NewSet(attributes...))
|
||||
return MetricOpts{
|
||||
opts["old"] = MetricOpts{
|
||||
measurement: set,
|
||||
addOptions: set,
|
||||
}
|
||||
|
||||
if c.duplicate {
|
||||
attributes := CurrentHTTPClient{}.MetricAttributes(ma.Req, ma.StatusCode, ma.AdditionalAttributes)
|
||||
set := metric.WithAttributeSet(attribute.NewSet(attributes...))
|
||||
opts["new"] = MetricOpts{
|
||||
measurement: set,
|
||||
addOptions: set,
|
||||
}
|
||||
}
|
||||
|
||||
return opts
|
||||
}
|
||||
|
||||
func (s HTTPClient) RecordMetrics(ctx context.Context, md MetricData, opts MetricOpts) {
|
||||
func (s HTTPClient) RecordMetrics(ctx context.Context, md MetricData, opts map[string]MetricOpts) {
|
||||
if s.requestBytesCounter == nil || s.latencyMeasure == nil {
|
||||
// This will happen if an HTTPClient{} is used instead of NewHTTPClient().
|
||||
return
|
||||
}
|
||||
|
||||
s.requestBytesCounter.Add(ctx, md.RequestSize, opts.AddOptions())
|
||||
s.latencyMeasure.Record(ctx, md.ElapsedTime, opts.MeasurementOption())
|
||||
s.requestBytesCounter.Add(ctx, md.RequestSize, opts["old"].AddOptions())
|
||||
s.latencyMeasure.Record(ctx, md.ElapsedTime, opts["old"].MeasurementOption())
|
||||
|
||||
// TODO: Duplicate Metrics
|
||||
if s.duplicate {
|
||||
s.requestBodySize.Record(ctx, md.RequestSize, opts["new"].MeasurementOption())
|
||||
s.requestDuration.Record(ctx, md.ElapsedTime, opts["new"].MeasurementOption())
|
||||
}
|
||||
}
|
||||
|
||||
func (s HTTPClient) RecordResponseSize(ctx context.Context, responseData int64, opts metric.AddOption) {
|
||||
func (s HTTPClient) RecordResponseSize(ctx context.Context, responseData int64, opts map[string]MetricOpts) {
|
||||
if s.responseBytesCounter == nil {
|
||||
// This will happen if an HTTPClient{} is used instead of NewHTTPClient().
|
||||
return
|
||||
}
|
||||
|
||||
s.responseBytesCounter.Add(ctx, responseData, opts)
|
||||
// TODO: Duplicate Metrics
|
||||
s.responseBytesCounter.Add(ctx, responseData, opts["old"].AddOptions())
|
||||
}
|
||||
|
||||
func (s HTTPClient) TraceAttributes(host string) []attribute.KeyValue {
|
||||
if s.duplicate {
|
||||
return append(OldHTTPClient{}.TraceAttributes(host), CurrentHTTPClient{}.TraceAttributes(host)...)
|
||||
}
|
||||
|
||||
return OldHTTPClient{}.TraceAttributes(host)
|
||||
}
|
||||
|
14
vendor/go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/internal/semconv/gen.go
generated
vendored
Normal file
14
vendor/go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/internal/semconv/gen.go
generated
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package semconv // import "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/internal/semconv"
|
||||
|
||||
// Generate semconv package:
|
||||
//go:generate gotmpl --body=../../../../../../internal/shared/semconv/bench_test.go.tmpl "--data={ \"pkg\": \"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp\" }" --out=bench_test.go
|
||||
//go:generate gotmpl --body=../../../../../../internal/shared/semconv/env.go.tmpl "--data={ \"pkg\": \"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp\" }" --out=env.go
|
||||
//go:generate gotmpl --body=../../../../../../internal/shared/semconv/env_test.go.tmpl "--data={ \"pkg\": \"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp\" }" --out=env_test.go
|
||||
//go:generate gotmpl --body=../../../../../../internal/shared/semconv/httpconv.go.tmpl "--data={ \"pkg\": \"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp\" }" --out=httpconv.go
|
||||
//go:generate gotmpl --body=../../../../../../internal/shared/semconv/httpconv_test.go.tmpl "--data={ \"pkg\": \"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp\" }" --out=httpconv_test.go
|
||||
//go:generate gotmpl --body=../../../../../../internal/shared/semconv/util.go.tmpl "--data={ \"pkg\": \"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp\" }" --out=util.go
|
||||
//go:generate gotmpl --body=../../../../../../internal/shared/semconv/util_test.go.tmpl "--data={ \"pkg\": \"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp\" }" --out=util_test.go
|
||||
//go:generate gotmpl --body=../../../../../../internal/shared/semconv/v1.20.0.go.tmpl "--data={ \"pkg\": \"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp\" }" --out=v1.20.0.go
|
@ -1,3 +1,6 @@
|
||||
// Code created by gotmpl. DO NOT MODIFY.
|
||||
// source: internal/shared/semconv/httpconv.go.tmpl
|
||||
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
@ -7,10 +10,13 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"reflect"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
"go.opentelemetry.io/otel/metric/noop"
|
||||
semconvNew "go.opentelemetry.io/otel/semconv/v1.26.0"
|
||||
)
|
||||
|
||||
@ -135,6 +141,19 @@ func (n CurrentHTTPServer) RequestTraceAttrs(server string, req *http.Request) [
|
||||
return attrs
|
||||
}
|
||||
|
||||
func (o CurrentHTTPServer) NetworkTransportAttr(network string) attribute.KeyValue {
|
||||
switch network {
|
||||
case "tcp", "tcp4", "tcp6":
|
||||
return semconvNew.NetworkTransportTCP
|
||||
case "udp", "udp4", "udp6":
|
||||
return semconvNew.NetworkTransportUDP
|
||||
case "unix", "unixgram", "unixpacket":
|
||||
return semconvNew.NetworkTransportUnix
|
||||
default:
|
||||
return semconvNew.NetworkTransportPipe
|
||||
}
|
||||
}
|
||||
|
||||
func (n CurrentHTTPServer) method(method string) (attribute.KeyValue, attribute.KeyValue) {
|
||||
if method == "" {
|
||||
return semconvNew.HTTPRequestMethodGet, attribute.KeyValue{}
|
||||
@ -199,6 +218,86 @@ func (n CurrentHTTPServer) Route(route string) attribute.KeyValue {
|
||||
return semconvNew.HTTPRoute(route)
|
||||
}
|
||||
|
||||
func (n CurrentHTTPServer) createMeasures(meter metric.Meter) (metric.Int64Histogram, metric.Int64Histogram, metric.Float64Histogram) {
|
||||
if meter == nil {
|
||||
return noop.Int64Histogram{}, noop.Int64Histogram{}, noop.Float64Histogram{}
|
||||
}
|
||||
|
||||
var err error
|
||||
requestBodySizeHistogram, err := meter.Int64Histogram(
|
||||
semconvNew.HTTPServerRequestBodySizeName,
|
||||
metric.WithUnit(semconvNew.HTTPServerRequestBodySizeUnit),
|
||||
metric.WithDescription(semconvNew.HTTPServerRequestBodySizeDescription),
|
||||
)
|
||||
handleErr(err)
|
||||
|
||||
responseBodySizeHistogram, err := meter.Int64Histogram(
|
||||
semconvNew.HTTPServerResponseBodySizeName,
|
||||
metric.WithUnit(semconvNew.HTTPServerResponseBodySizeUnit),
|
||||
metric.WithDescription(semconvNew.HTTPServerResponseBodySizeDescription),
|
||||
)
|
||||
handleErr(err)
|
||||
requestDurationHistogram, err := meter.Float64Histogram(
|
||||
semconvNew.HTTPServerRequestDurationName,
|
||||
metric.WithUnit(semconvNew.HTTPServerRequestDurationUnit),
|
||||
metric.WithDescription(semconvNew.HTTPServerRequestDurationDescription),
|
||||
)
|
||||
handleErr(err)
|
||||
|
||||
return requestBodySizeHistogram, responseBodySizeHistogram, requestDurationHistogram
|
||||
}
|
||||
|
||||
func (n CurrentHTTPServer) MetricAttributes(server string, req *http.Request, statusCode int, additionalAttributes []attribute.KeyValue) []attribute.KeyValue {
|
||||
num := len(additionalAttributes) + 3
|
||||
var host string
|
||||
var p int
|
||||
if server == "" {
|
||||
host, p = SplitHostPort(req.Host)
|
||||
} else {
|
||||
// Prioritize the primary server name.
|
||||
host, p = SplitHostPort(server)
|
||||
if p < 0 {
|
||||
_, p = SplitHostPort(req.Host)
|
||||
}
|
||||
}
|
||||
hostPort := requiredHTTPPort(req.TLS != nil, p)
|
||||
if hostPort > 0 {
|
||||
num++
|
||||
}
|
||||
protoName, protoVersion := netProtocol(req.Proto)
|
||||
if protoName != "" {
|
||||
num++
|
||||
}
|
||||
if protoVersion != "" {
|
||||
num++
|
||||
}
|
||||
|
||||
if statusCode > 0 {
|
||||
num++
|
||||
}
|
||||
|
||||
attributes := slices.Grow(additionalAttributes, num)
|
||||
attributes = append(attributes,
|
||||
semconvNew.HTTPRequestMethodKey.String(standardizeHTTPMethod(req.Method)),
|
||||
n.scheme(req.TLS != nil),
|
||||
semconvNew.ServerAddress(host))
|
||||
|
||||
if hostPort > 0 {
|
||||
attributes = append(attributes, semconvNew.ServerPort(hostPort))
|
||||
}
|
||||
if protoName != "" {
|
||||
attributes = append(attributes, semconvNew.NetworkProtocolName(protoName))
|
||||
}
|
||||
if protoVersion != "" {
|
||||
attributes = append(attributes, semconvNew.NetworkProtocolVersion(protoVersion))
|
||||
}
|
||||
|
||||
if statusCode > 0 {
|
||||
attributes = append(attributes, semconvNew.HTTPResponseStatusCode(statusCode))
|
||||
}
|
||||
return attributes
|
||||
}
|
||||
|
||||
type CurrentHTTPClient struct{}
|
||||
|
||||
// RequestTraceAttrs returns trace attributes for an HTTP request made by a client.
|
||||
@ -343,6 +442,98 @@ func (n CurrentHTTPClient) method(method string) (attribute.KeyValue, attribute.
|
||||
return semconvNew.HTTPRequestMethodGet, orig
|
||||
}
|
||||
|
||||
func (n CurrentHTTPClient) createMeasures(meter metric.Meter) (metric.Int64Histogram, metric.Float64Histogram) {
|
||||
if meter == nil {
|
||||
return noop.Int64Histogram{}, noop.Float64Histogram{}
|
||||
}
|
||||
|
||||
var err error
|
||||
requestBodySize, err := meter.Int64Histogram(
|
||||
semconvNew.HTTPClientRequestBodySizeName,
|
||||
metric.WithUnit(semconvNew.HTTPClientRequestBodySizeUnit),
|
||||
metric.WithDescription(semconvNew.HTTPClientRequestBodySizeDescription),
|
||||
)
|
||||
handleErr(err)
|
||||
|
||||
requestDuration, err := meter.Float64Histogram(
|
||||
semconvNew.HTTPClientRequestDurationName,
|
||||
metric.WithUnit(semconvNew.HTTPClientRequestDurationUnit),
|
||||
metric.WithDescription(semconvNew.HTTPClientRequestDurationDescription),
|
||||
)
|
||||
handleErr(err)
|
||||
|
||||
return requestBodySize, requestDuration
|
||||
}
|
||||
|
||||
func (n CurrentHTTPClient) MetricAttributes(req *http.Request, statusCode int, additionalAttributes []attribute.KeyValue) []attribute.KeyValue {
|
||||
num := len(additionalAttributes) + 2
|
||||
var h string
|
||||
if req.URL != nil {
|
||||
h = req.URL.Host
|
||||
}
|
||||
var requestHost string
|
||||
var requestPort int
|
||||
for _, hostport := range []string{h, req.Header.Get("Host")} {
|
||||
requestHost, requestPort = SplitHostPort(hostport)
|
||||
if requestHost != "" || requestPort > 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
port := requiredHTTPPort(req.URL != nil && req.URL.Scheme == "https", requestPort)
|
||||
if port > 0 {
|
||||
num++
|
||||
}
|
||||
|
||||
protoName, protoVersion := netProtocol(req.Proto)
|
||||
if protoName != "" {
|
||||
num++
|
||||
}
|
||||
if protoVersion != "" {
|
||||
num++
|
||||
}
|
||||
|
||||
if statusCode > 0 {
|
||||
num++
|
||||
}
|
||||
|
||||
attributes := slices.Grow(additionalAttributes, num)
|
||||
attributes = append(attributes,
|
||||
semconvNew.HTTPRequestMethodKey.String(standardizeHTTPMethod(req.Method)),
|
||||
semconvNew.ServerAddress(requestHost),
|
||||
n.scheme(req.TLS != nil),
|
||||
)
|
||||
|
||||
if port > 0 {
|
||||
attributes = append(attributes, semconvNew.ServerPort(port))
|
||||
}
|
||||
if protoName != "" {
|
||||
attributes = append(attributes, semconvNew.NetworkProtocolName(protoName))
|
||||
}
|
||||
if protoVersion != "" {
|
||||
attributes = append(attributes, semconvNew.NetworkProtocolVersion(protoVersion))
|
||||
}
|
||||
|
||||
if statusCode > 0 {
|
||||
attributes = append(attributes, semconvNew.HTTPResponseStatusCode(statusCode))
|
||||
}
|
||||
return attributes
|
||||
}
|
||||
|
||||
// Attributes for httptrace.
|
||||
func (n CurrentHTTPClient) TraceAttributes(host string) []attribute.KeyValue {
|
||||
return []attribute.KeyValue{
|
||||
semconvNew.ServerAddress(host),
|
||||
}
|
||||
}
|
||||
|
||||
func (n CurrentHTTPClient) scheme(https bool) attribute.KeyValue { // nolint:revive
|
||||
if https {
|
||||
return semconvNew.URLScheme("https")
|
||||
}
|
||||
return semconvNew.URLScheme("http")
|
||||
}
|
||||
|
||||
func isErrorStatusCode(code int) bool {
|
||||
return code >= 400 || code < 100
|
||||
}
|
||||
|
@ -1,3 +1,6 @@
|
||||
// Code created by gotmpl. DO NOT MODIFY.
|
||||
// source: internal/shared/semconv/util.go.tmpl
|
||||
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
@ -75,7 +78,16 @@ func serverClientIP(xForwardedFor string) string {
|
||||
|
||||
func netProtocol(proto string) (name string, version string) {
|
||||
name, version, _ = strings.Cut(proto, "/")
|
||||
name = strings.ToLower(name)
|
||||
switch name {
|
||||
case "HTTP":
|
||||
name = "http"
|
||||
case "QUIC":
|
||||
name = "quic"
|
||||
case "SPDY":
|
||||
name = "spdy"
|
||||
default:
|
||||
name = strings.ToLower(name)
|
||||
}
|
||||
return name, version
|
||||
}
|
||||
|
||||
@ -96,3 +108,13 @@ func handleErr(err error) {
|
||||
otel.Handle(err)
|
||||
}
|
||||
}
|
||||
|
||||
func standardizeHTTPMethod(method string) string {
|
||||
method = strings.ToUpper(method)
|
||||
switch method {
|
||||
case http.MethodConnect, http.MethodDelete, http.MethodGet, http.MethodHead, http.MethodOptions, http.MethodPatch, http.MethodPost, http.MethodPut, http.MethodTrace:
|
||||
default:
|
||||
method = "_OTHER"
|
||||
}
|
||||
return method
|
||||
}
|
||||
|
@ -1,3 +1,6 @@
|
||||
// Code created by gotmpl. DO NOT MODIFY.
|
||||
// source: internal/shared/semconv/v120.0.go.tmpl
|
||||
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
@ -8,7 +11,6 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/internal/semconvutil"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
@ -39,6 +41,10 @@ func (o OldHTTPServer) RequestTraceAttrs(server string, req *http.Request) []att
|
||||
return semconvutil.HTTPServerRequest(server, req)
|
||||
}
|
||||
|
||||
func (o OldHTTPServer) NetworkTransportAttr(network string) attribute.KeyValue {
|
||||
return semconvutil.NetTransport(network)
|
||||
}
|
||||
|
||||
// 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.
|
||||
@ -144,7 +150,7 @@ func (o OldHTTPServer) MetricAttributes(server string, req *http.Request, status
|
||||
|
||||
attributes := slices.Grow(additionalAttributes, n)
|
||||
attributes = append(attributes,
|
||||
standardizeHTTPMethodMetric(req.Method),
|
||||
semconv.HTTPMethod(standardizeHTTPMethod(req.Method)),
|
||||
o.scheme(req.TLS != nil),
|
||||
semconv.NetHostName(host))
|
||||
|
||||
@ -214,7 +220,7 @@ func (o OldHTTPClient) MetricAttributes(req *http.Request, statusCode int, addit
|
||||
|
||||
attributes := slices.Grow(additionalAttributes, n)
|
||||
attributes = append(attributes,
|
||||
standardizeHTTPMethodMetric(req.Method),
|
||||
semconv.HTTPMethod(standardizeHTTPMethod(req.Method)),
|
||||
semconv.NetPeerName(requestHost),
|
||||
)
|
||||
|
||||
@ -263,12 +269,9 @@ func (o OldHTTPClient) createMeasures(meter metric.Meter) (metric.Int64Counter,
|
||||
return requestBytesCounter, responseBytesCounter, latencyMeasure
|
||||
}
|
||||
|
||||
func standardizeHTTPMethodMetric(method string) attribute.KeyValue {
|
||||
method = strings.ToUpper(method)
|
||||
switch method {
|
||||
case http.MethodConnect, http.MethodDelete, http.MethodGet, http.MethodHead, http.MethodOptions, http.MethodPatch, http.MethodPost, http.MethodPut, http.MethodTrace:
|
||||
default:
|
||||
method = "_OTHER"
|
||||
// Attributes for httptrace.
|
||||
func (c OldHTTPClient) TraceAttributes(host string) []attribute.KeyValue {
|
||||
return []attribute.KeyValue{
|
||||
semconv.NetHostName(host),
|
||||
}
|
||||
return semconv.HTTPMethod(method)
|
||||
}
|
||||
|
@ -200,6 +200,15 @@ func splitHostPort(hostport string) (host string, port int) {
|
||||
|
||||
func netProtocol(proto string) (name string, version string) {
|
||||
name, version, _ = strings.Cut(proto, "/")
|
||||
name = strings.ToLower(name)
|
||||
switch name {
|
||||
case "HTTP":
|
||||
name = "http"
|
||||
case "QUIC":
|
||||
name = "quic"
|
||||
case "SPDY":
|
||||
name = "spdy"
|
||||
default:
|
||||
name = strings.ToLower(name)
|
||||
}
|
||||
return name, version
|
||||
}
|
||||
|
2
vendor/go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/transport.go
generated
vendored
2
vendor/go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/transport.go
generated
vendored
@ -153,7 +153,7 @@ func (t *Transport) RoundTrip(r *http.Request) (*http.Response, error) {
|
||||
|
||||
// For handling response bytes we leverage a callback when the client reads the http response
|
||||
readRecordFunc := func(n int64) {
|
||||
t.semconv.RecordResponseSize(ctx, n, metricOpts.AddOptions())
|
||||
t.semconv.RecordResponseSize(ctx, n, metricOpts)
|
||||
}
|
||||
|
||||
// traces
|
||||
|
2
vendor/go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/version.go
generated
vendored
2
vendor/go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/version.go
generated
vendored
@ -5,7 +5,7 @@ package otelhttp // import "go.opentelemetry.io/contrib/instrumentation/net/http
|
||||
|
||||
// Version is the current release version of the otelhttp instrumentation.
|
||||
func Version() string {
|
||||
return "0.58.0"
|
||||
return "0.60.0"
|
||||
// This string is updated by the pre_release.sh script during release
|
||||
}
|
||||
|
||||
|
1
vendor/go.opentelemetry.io/otel/.gitignore
generated
vendored
1
vendor/go.opentelemetry.io/otel/.gitignore
generated
vendored
@ -1,6 +1,7 @@
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
.cache/
|
||||
.tools/
|
||||
venv/
|
||||
.idea/
|
||||
|
105
vendor/go.opentelemetry.io/otel/.golangci.yml
generated
vendored
105
vendor/go.opentelemetry.io/otel/.golangci.yml
generated
vendored
@ -25,13 +25,13 @@ linters:
|
||||
- perfsprint
|
||||
- revive
|
||||
- staticcheck
|
||||
- tenv
|
||||
- testifylint
|
||||
- typecheck
|
||||
- unconvert
|
||||
- unused
|
||||
- unparam
|
||||
- usestdlibvars
|
||||
- usetesting
|
||||
|
||||
issues:
|
||||
# Maximum issues count per one linter.
|
||||
@ -175,132 +175,60 @@ linters-settings:
|
||||
# This means that linting errors with less than 0.8 confidence will be ignored.
|
||||
# Default: 0.8
|
||||
confidence: 0.01
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md
|
||||
rules:
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#blank-imports
|
||||
- name: blank-imports
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#bool-literal-in-expr
|
||||
- name: bool-literal-in-expr
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#constant-logical-expr
|
||||
- name: constant-logical-expr
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#context-as-argument
|
||||
# TODO (#3372) re-enable linter when it is compatible. https://github.com/golangci/golangci-lint/issues/3280
|
||||
- name: context-as-argument
|
||||
disabled: true
|
||||
arguments:
|
||||
allowTypesBefore: "*testing.T"
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#context-keys-type
|
||||
- allowTypesBefore: "*testing.T"
|
||||
- name: context-keys-type
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#deep-exit
|
||||
- name: deep-exit
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#defer
|
||||
- name: defer
|
||||
disabled: false
|
||||
arguments:
|
||||
- ["call-chain", "loop"]
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#dot-imports
|
||||
- name: dot-imports
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#duplicated-imports
|
||||
- name: duplicated-imports
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#early-return
|
||||
- name: early-return
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#empty-block
|
||||
arguments:
|
||||
- "preserveScope"
|
||||
- name: empty-block
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#empty-lines
|
||||
- name: empty-lines
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#error-naming
|
||||
- name: error-naming
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#error-return
|
||||
- name: error-return
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#error-strings
|
||||
- name: error-strings
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#errorf
|
||||
- name: errorf
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#exported
|
||||
- name: exported
|
||||
disabled: false
|
||||
arguments:
|
||||
- "sayRepetitiveInsteadOfStutters"
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#flag-parameter
|
||||
- name: flag-parameter
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#identical-branches
|
||||
- name: identical-branches
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#if-return
|
||||
- name: if-return
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#increment-decrement
|
||||
- name: increment-decrement
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#indent-error-flow
|
||||
- name: indent-error-flow
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#import-shadowing
|
||||
- name: import-shadowing
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#package-comments
|
||||
- name: increment-decrement
|
||||
- name: indent-error-flow
|
||||
arguments:
|
||||
- "preserveScope"
|
||||
- name: package-comments
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#range
|
||||
- name: range
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#range-val-in-closure
|
||||
- name: range-val-in-closure
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#range-val-address
|
||||
- name: range-val-address
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#redefines-builtin-id
|
||||
- name: redefines-builtin-id
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#string-format
|
||||
- name: string-format
|
||||
disabled: false
|
||||
arguments:
|
||||
- - panic
|
||||
- '/^[^\n]*$/'
|
||||
- must not contain line breaks
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#struct-tag
|
||||
- name: struct-tag
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#superfluous-else
|
||||
- name: superfluous-else
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#time-equal
|
||||
- name: time-equal
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#var-naming
|
||||
- name: var-naming
|
||||
disabled: false
|
||||
arguments:
|
||||
- ["ID"] # AllowList
|
||||
- ["Otel", "Aws", "Gcp"] # DenyList
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#var-declaration
|
||||
- name: var-declaration
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unconditional-recursion
|
||||
- "preserveScope"
|
||||
- name: time-equal
|
||||
- name: unconditional-recursion
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unexported-return
|
||||
- name: unexported-return
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unhandled-error
|
||||
- name: unhandled-error
|
||||
disabled: false
|
||||
arguments:
|
||||
- "fmt.Fprint"
|
||||
- "fmt.Fprintf"
|
||||
@ -308,15 +236,14 @@ linters-settings:
|
||||
- "fmt.Print"
|
||||
- "fmt.Printf"
|
||||
- "fmt.Println"
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unnecessary-stmt
|
||||
- name: unnecessary-stmt
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#useless-break
|
||||
- name: useless-break
|
||||
disabled: false
|
||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#waitgroup-by-value
|
||||
- name: var-declaration
|
||||
- name: var-naming
|
||||
arguments:
|
||||
- ["ID"] # AllowList
|
||||
- ["Otel", "Aws", "Gcp"] # DenyList
|
||||
- name: waitgroup-by-value
|
||||
disabled: false
|
||||
testifylint:
|
||||
enable-all: true
|
||||
disable:
|
||||
|
63
vendor/go.opentelemetry.io/otel/CHANGELOG.md
generated
vendored
63
vendor/go.opentelemetry.io/otel/CHANGELOG.md
generated
vendored
@ -8,6 +8,61 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
<!-- Released section -->
|
||||
<!-- Don't change this section unless doing release -->
|
||||
|
||||
## [1.35.0/0.57.0/0.11.0] 2025-03-05
|
||||
|
||||
This release is the last to support [Go 1.22].
|
||||
The next release will require at least [Go 1.23].
|
||||
|
||||
### Added
|
||||
|
||||
- Add `ValueFromAttribute` and `KeyValueFromAttribute` in `go.opentelemetry.io/otel/log`. (#6180)
|
||||
- Add `EventName` and `SetEventName` to `Record` in `go.opentelemetry.io/otel/log`. (#6187)
|
||||
- Add `EventName` to `RecordFactory` in `go.opentelemetry.io/otel/log/logtest`. (#6187)
|
||||
- `AssertRecordEqual` in `go.opentelemetry.io/otel/log/logtest` checks `Record.EventName`. (#6187)
|
||||
- Add `EventName` and `SetEventName` to `Record` in `go.opentelemetry.io/otel/sdk/log`. (#6193)
|
||||
- Add `EventName` to `RecordFactory` in `go.opentelemetry.io/otel/sdk/log/logtest`. (#6193)
|
||||
- Emit `Record.EventName` field in `go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc`. (#6211)
|
||||
- Emit `Record.EventName` field in `go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp`. (#6211)
|
||||
- Emit `Record.EventName` field in `go.opentelemetry.io/otel/exporters/stdout/stdoutlog` (#6210)
|
||||
- The `go.opentelemetry.io/otel/semconv/v1.28.0` package.
|
||||
The package contains semantic conventions from the `v1.28.0` version of the OpenTelemetry Semantic Conventions.
|
||||
See the [migration documentation](./semconv/v1.28.0/MIGRATION.md) for information on how to upgrade from `go.opentelemetry.io/otel/semconv/v1.27.0`(#6236)
|
||||
- The `go.opentelemetry.io/otel/semconv/v1.30.0` package.
|
||||
The package contains semantic conventions from the `v1.30.0` version of the OpenTelemetry Semantic Conventions.
|
||||
See the [migration documentation](./semconv/v1.30.0/MIGRATION.md) for information on how to upgrade from `go.opentelemetry.io/otel/semconv/v1.28.0`(#6240)
|
||||
- Document the pitfalls of using `Resource` as a comparable type.
|
||||
`Resource.Equal` and `Resource.Equivalent` should be used instead. (#6272)
|
||||
- Support [Go 1.24]. (#6304)
|
||||
- Add `FilterProcessor` and `EnabledParameters` in `go.opentelemetry.io/otel/sdk/log`.
|
||||
It replaces `go.opentelemetry.io/otel/sdk/log/internal/x.FilterProcessor`.
|
||||
Compared to previous version it additionally gives the possibility to filter by resource and instrumentation scope. (#6317)
|
||||
|
||||
### Changed
|
||||
|
||||
- Update `github.com/prometheus/common` to `v0.62.0`, which changes the `NameValidationScheme` to `NoEscaping`.
|
||||
This allows metrics names to keep original delimiters (e.g. `.`), rather than replacing with underscores.
|
||||
This is controlled by the `Content-Type` header, or can be reverted by setting `NameValidationScheme` to `LegacyValidation` in `github.com/prometheus/common/model`. (#6198)
|
||||
|
||||
### Fixes
|
||||
|
||||
- Eliminate goroutine leak for the processor returned by `NewSimpleSpanProcessor` in `go.opentelemetry.io/otel/sdk/trace` when `Shutdown` is called and the passed `ctx` is canceled and `SpanExporter.Shutdown` has not returned. (#6368)
|
||||
- Eliminate goroutine leak for the processor returned by `NewBatchSpanProcessor` in `go.opentelemetry.io/otel/sdk/trace` when `ForceFlush` is called and the passed `ctx` is canceled and `SpanExporter.Export` has not returned. (#6369)
|
||||
|
||||
## [1.34.0/0.56.0/0.10.0] 2025-01-17
|
||||
|
||||
### Changed
|
||||
|
||||
- Remove the notices from `Logger` to make the whole Logs API user-facing in `go.opentelemetry.io/otel/log`. (#6167)
|
||||
|
||||
### Fixed
|
||||
|
||||
- Relax minimum Go version to 1.22.0 in various modules. (#6073)
|
||||
- The `Type` name logged for the `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc` client is corrected from `otlphttpgrpc` to `otlptracegrpc`. (#6143)
|
||||
- The `Type` name logged for the `go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlphttpgrpc` client is corrected from `otlphttphttp` to `otlptracehttp`. (#6143)
|
||||
|
||||
## [1.33.0/0.55.0/0.9.0/0.0.12] 2024-12-12
|
||||
|
||||
### Added
|
||||
@ -37,9 +92,6 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
||||
- Fix attribute value truncation in `go.opentelemetry.io/otel/sdk/trace`. (#5997)
|
||||
- Fix attribute value truncation in `go.opentelemetry.io/otel/sdk/log`. (#6032)
|
||||
|
||||
<!-- Released section -->
|
||||
<!-- Don't change this section unless doing release -->
|
||||
|
||||
## [1.32.0/0.54.0/0.8.0/0.0.11] 2024-11-08
|
||||
|
||||
### Added
|
||||
@ -3185,7 +3237,9 @@ It contains api and sdk for trace and meter.
|
||||
- CircleCI build CI manifest files.
|
||||
- CODEOWNERS file to track owners of this project.
|
||||
|
||||
[Unreleased]: https://github.com/open-telemetry/opentelemetry-go/compare/v1.33.0...HEAD
|
||||
[Unreleased]: https://github.com/open-telemetry/opentelemetry-go/compare/v1.35.0...HEAD
|
||||
[1.35.0/0.57.0/0.11.0]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v1.35.0
|
||||
[1.34.0/0.56.0/0.10.0]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v1.34.0
|
||||
[1.33.0/0.55.0/0.9.0/0.0.12]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v1.33.0
|
||||
[1.32.0/0.54.0/0.8.0/0.0.11]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v1.32.0
|
||||
[1.31.0/0.53.0/0.7.0/0.0.10]: https://github.com/open-telemetry/opentelemetry-go/releases/tag/v1.31.0
|
||||
@ -3275,6 +3329,7 @@ It contains api and sdk for trace and meter.
|
||||
|
||||
<!-- Released section ended -->
|
||||
|
||||
[Go 1.24]: https://go.dev/doc/go1.24
|
||||
[Go 1.23]: https://go.dev/doc/go1.23
|
||||
[Go 1.22]: https://go.dev/doc/go1.22
|
||||
[Go 1.21]: https://go.dev/doc/go1.21
|
||||
|
12
vendor/go.opentelemetry.io/otel/CONTRIBUTING.md
generated
vendored
12
vendor/go.opentelemetry.io/otel/CONTRIBUTING.md
generated
vendored
@ -181,6 +181,18 @@ patterns in the spec.
|
||||
For a deeper discussion, see
|
||||
[this](https://github.com/open-telemetry/opentelemetry-specification/issues/165).
|
||||
|
||||
## Tests
|
||||
|
||||
Each functionality should be covered by tests.
|
||||
|
||||
Performance-critical functionality should also be covered by benchmarks.
|
||||
|
||||
- Pull requests adding a performance-critical functionality
|
||||
should have `go test -bench` output in their description.
|
||||
- Pull requests changing a performance-critical functionality
|
||||
should have [`benchstat`](https://pkg.go.dev/golang.org/x/perf/cmd/benchstat)
|
||||
output in their description.
|
||||
|
||||
## Documentation
|
||||
|
||||
Each (non-internal, non-test) package must be documented using
|
||||
|
39
vendor/go.opentelemetry.io/otel/Makefile
generated
vendored
39
vendor/go.opentelemetry.io/otel/Makefile
generated
vendored
@ -11,6 +11,10 @@ ALL_COVERAGE_MOD_DIRS := $(shell find . -type f -name 'go.mod' -exec dirname {}
|
||||
GO = go
|
||||
TIMEOUT = 60
|
||||
|
||||
# User to run as in docker images.
|
||||
DOCKER_USER=$(shell id -u):$(shell id -g)
|
||||
DEPENDENCIES_DOCKERFILE=./dependencies.Dockerfile
|
||||
|
||||
.DEFAULT_GOAL := precommit
|
||||
|
||||
.PHONY: precommit ci
|
||||
@ -81,20 +85,20 @@ PIP := $(PYTOOLS)/pip
|
||||
WORKDIR := /workdir
|
||||
|
||||
# The python image to use for the virtual environment.
|
||||
PYTHONIMAGE := python:3.11.3-slim-bullseye
|
||||
PYTHONIMAGE := $(shell awk '$$4=="python" {print $$2}' $(DEPENDENCIES_DOCKERFILE))
|
||||
|
||||
# Run the python image with the current directory mounted.
|
||||
DOCKERPY := docker run --rm -v "$(CURDIR):$(WORKDIR)" -w $(WORKDIR) $(PYTHONIMAGE)
|
||||
DOCKERPY := docker run --rm -u $(DOCKER_USER) -v "$(CURDIR):$(WORKDIR)" -w $(WORKDIR) $(PYTHONIMAGE)
|
||||
|
||||
# Create a virtual environment for Python tools.
|
||||
$(PYTOOLS):
|
||||
# The `--upgrade` flag is needed to ensure that the virtual environment is
|
||||
# created with the latest pip version.
|
||||
@$(DOCKERPY) bash -c "python3 -m venv $(VENVDIR) && $(PIP) install --upgrade pip"
|
||||
@$(DOCKERPY) bash -c "python3 -m venv $(VENVDIR) && $(PIP) install --upgrade --cache-dir=$(WORKDIR)/.cache/pip pip"
|
||||
|
||||
# Install python packages into the virtual environment.
|
||||
$(PYTOOLS)/%: $(PYTOOLS)
|
||||
@$(DOCKERPY) $(PIP) install -r requirements.txt
|
||||
@$(DOCKERPY) $(PIP) install --cache-dir=$(WORKDIR)/.cache/pip -r requirements.txt
|
||||
|
||||
CODESPELL = $(PYTOOLS)/codespell
|
||||
$(CODESPELL): PACKAGE=codespell
|
||||
@ -119,7 +123,7 @@ vanity-import-fix: $(PORTO)
|
||||
# Generate go.work file for local development.
|
||||
.PHONY: go-work
|
||||
go-work: $(CROSSLINK)
|
||||
$(CROSSLINK) work --root=$(shell pwd)
|
||||
$(CROSSLINK) work --root=$(shell pwd) --go=1.22.7
|
||||
|
||||
# Build
|
||||
|
||||
@ -265,13 +269,30 @@ check-clean-work-tree:
|
||||
exit 1; \
|
||||
fi
|
||||
|
||||
# The weaver docker image to use for semconv-generate.
|
||||
WEAVER_IMAGE := $(shell awk '$$4=="weaver" {print $$2}' $(DEPENDENCIES_DOCKERFILE))
|
||||
|
||||
SEMCONVPKG ?= "semconv/"
|
||||
.PHONY: semconv-generate
|
||||
semconv-generate: $(SEMCONVGEN) $(SEMCONVKIT)
|
||||
semconv-generate: $(SEMCONVKIT)
|
||||
[ "$(TAG)" ] || ( echo "TAG unset: missing opentelemetry semantic-conventions tag"; exit 1 )
|
||||
[ "$(OTEL_SEMCONV_REPO)" ] || ( echo "OTEL_SEMCONV_REPO unset: missing path to opentelemetry semantic-conventions repo"; exit 1 )
|
||||
$(SEMCONVGEN) -i "$(OTEL_SEMCONV_REPO)/model/." --only=attribute_group -p conventionType=trace -f attribute_group.go -z "$(SEMCONVPKG)/capitalizations.txt" -t "$(SEMCONVPKG)/template.j2" -s "$(TAG)"
|
||||
$(SEMCONVGEN) -i "$(OTEL_SEMCONV_REPO)/model/." --only=metric -f metric.go -t "$(SEMCONVPKG)/metric_template.j2" -s "$(TAG)"
|
||||
# Ensure the target directory for source code is available.
|
||||
mkdir -p $(PWD)/$(SEMCONVPKG)/${TAG}
|
||||
# Note: We mount a home directory for downloading/storing the semconv repository.
|
||||
# Weaver will automatically clean the cache when finished, but the directories will remain.
|
||||
mkdir -p ~/.weaver
|
||||
docker run --rm \
|
||||
-u $(DOCKER_USER) \
|
||||
--env HOME=/tmp/weaver \
|
||||
--mount 'type=bind,source=$(PWD)/semconv,target=/home/weaver/templates/registry/go,readonly' \
|
||||
--mount 'type=bind,source=$(PWD)/semconv/${TAG},target=/home/weaver/target' \
|
||||
--mount 'type=bind,source=$(HOME)/.weaver,target=/tmp/weaver/.weaver' \
|
||||
$(WEAVER_IMAGE) registry generate \
|
||||
--registry=https://github.com/open-telemetry/semantic-conventions/archive/refs/tags/$(TAG).zip[model] \
|
||||
--templates=/home/weaver/templates \
|
||||
--param tag=$(TAG) \
|
||||
go \
|
||||
/home/weaver/target
|
||||
$(SEMCONVKIT) -output "$(SEMCONVPKG)/$(TAG)" -tag "$(TAG)"
|
||||
|
||||
.PHONY: gorelease
|
||||
|
15
vendor/go.opentelemetry.io/otel/README.md
generated
vendored
15
vendor/go.opentelemetry.io/otel/README.md
generated
vendored
@ -1,9 +1,11 @@
|
||||
# OpenTelemetry-Go
|
||||
|
||||
[](https://github.com/open-telemetry/opentelemetry-go/actions?query=workflow%3Aci+branch%3Amain)
|
||||
[](https://github.com/open-telemetry/opentelemetry-go/actions/workflows/ci.yml)
|
||||
[](https://app.codecov.io/gh/open-telemetry/opentelemetry-go?branch=main)
|
||||
[](https://pkg.go.dev/go.opentelemetry.io/otel)
|
||||
[](https://goreportcard.com/report/go.opentelemetry.io/otel)
|
||||
[](https://scorecard.dev/viewer/?uri=github.com/open-telemetry/opentelemetry-go)
|
||||
[](https://www.bestpractices.dev/projects/9996)
|
||||
[](https://cloud-native.slack.com/archives/C01NPAXACKT)
|
||||
|
||||
OpenTelemetry-Go is the [Go](https://golang.org/) implementation of [OpenTelemetry](https://opentelemetry.io/).
|
||||
@ -49,18 +51,25 @@ Currently, this project supports the following environments.
|
||||
|
||||
| OS | Go Version | Architecture |
|
||||
|----------|------------|--------------|
|
||||
| Ubuntu | 1.24 | amd64 |
|
||||
| Ubuntu | 1.23 | amd64 |
|
||||
| Ubuntu | 1.22 | amd64 |
|
||||
| Ubuntu | 1.24 | 386 |
|
||||
| Ubuntu | 1.23 | 386 |
|
||||
| Ubuntu | 1.22 | 386 |
|
||||
| Linux | 1.23 | arm64 |
|
||||
| Linux | 1.22 | arm64 |
|
||||
| Ubuntu | 1.24 | arm64 |
|
||||
| Ubuntu | 1.23 | arm64 |
|
||||
| Ubuntu | 1.22 | arm64 |
|
||||
| macOS 13 | 1.24 | amd64 |
|
||||
| macOS 13 | 1.23 | amd64 |
|
||||
| macOS 13 | 1.22 | amd64 |
|
||||
| macOS | 1.24 | arm64 |
|
||||
| macOS | 1.23 | arm64 |
|
||||
| macOS | 1.22 | arm64 |
|
||||
| Windows | 1.24 | amd64 |
|
||||
| Windows | 1.23 | amd64 |
|
||||
| Windows | 1.22 | amd64 |
|
||||
| Windows | 1.24 | 386 |
|
||||
| Windows | 1.23 | 386 |
|
||||
| Windows | 1.22 | 386 |
|
||||
|
||||
|
17
vendor/go.opentelemetry.io/otel/RELEASING.md
generated
vendored
17
vendor/go.opentelemetry.io/otel/RELEASING.md
generated
vendored
@ -5,17 +5,14 @@
|
||||
New versions of the [OpenTelemetry Semantic Conventions] mean new versions of the `semconv` package need to be generated.
|
||||
The `semconv-generate` make target is used for this.
|
||||
|
||||
1. Checkout a local copy of the [OpenTelemetry Semantic Conventions] to the desired release tag.
|
||||
2. Pull the latest `otel/semconvgen` image: `docker pull otel/semconvgen:latest`
|
||||
3. Run the `make semconv-generate ...` target from this repository.
|
||||
1. Set the `TAG` environment variable to the semantic convention tag you want to generate.
|
||||
2. Run the `make semconv-generate ...` target from this repository.
|
||||
|
||||
For example,
|
||||
|
||||
```sh
|
||||
export TAG="v1.21.0" # Change to the release version you are generating.
|
||||
export OTEL_SEMCONV_REPO="/absolute/path/to/opentelemetry/semantic-conventions"
|
||||
docker pull otel/semconvgen:latest
|
||||
make semconv-generate # Uses the exported TAG and OTEL_SEMCONV_REPO.
|
||||
export TAG="v1.30.0" # Change to the release version you are generating.
|
||||
make semconv-generate # Uses the exported TAG.
|
||||
```
|
||||
|
||||
This should create a new sub-package of [`semconv`](./semconv).
|
||||
@ -130,6 +127,6 @@ Importantly, bump any package versions referenced to be the latest one you just
|
||||
|
||||
Bump the dependencies in the following Go services:
|
||||
|
||||
- [`accountingservice`](https://github.com/open-telemetry/opentelemetry-demo/tree/main/src/accountingservice)
|
||||
- [`checkoutservice`](https://github.com/open-telemetry/opentelemetry-demo/tree/main/src/checkoutservice)
|
||||
- [`productcatalogservice`](https://github.com/open-telemetry/opentelemetry-demo/tree/main/src/productcatalogservice)
|
||||
- [`accounting`](https://github.com/open-telemetry/opentelemetry-demo/tree/main/src/accounting)
|
||||
- [`checkoutservice`](https://github.com/open-telemetry/opentelemetry-demo/tree/main/src/checkout)
|
||||
- [`productcatalogservice`](https://github.com/open-telemetry/opentelemetry-demo/tree/main/src/product-catalog)
|
||||
|
3
vendor/go.opentelemetry.io/otel/dependencies.Dockerfile
generated
vendored
Normal file
3
vendor/go.opentelemetry.io/otel/dependencies.Dockerfile
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
# This is a renovate-friendly source of Docker images.
|
||||
FROM python:3.13.2-slim-bullseye@sha256:31b581c8218e1f3c58672481b3b7dba8e898852866b408c6a984c22832523935 AS python
|
||||
FROM otel/weaver:v0.13.2@sha256:ae7346b992e477f629ea327e0979e8a416a97f7956ab1f7e95ac1f44edf1a893 AS weaver
|
2
vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/version.go
generated
vendored
2
vendor/go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc/version.go
generated
vendored
@ -5,5 +5,5 @@ package otlpmetricgrpc // import "go.opentelemetry.io/otel/exporters/otlp/otlpme
|
||||
|
||||
// Version is the current release version of the OpenTelemetry OTLP over gRPC metrics exporter in use.
|
||||
func Version() string {
|
||||
return "1.33.0"
|
||||
return "1.35.0"
|
||||
}
|
||||
|
2
vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/client.go
generated
vendored
2
vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/client.go
generated
vendored
@ -294,7 +294,7 @@ func (c *client) MarshalLog() interface{} {
|
||||
Type string
|
||||
Endpoint string
|
||||
}{
|
||||
Type: "otlphttpgrpc",
|
||||
Type: "otlptracegrpc",
|
||||
Endpoint: c.endpoint,
|
||||
}
|
||||
}
|
||||
|
2
vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/version.go
generated
vendored
2
vendor/go.opentelemetry.io/otel/exporters/otlp/otlptrace/version.go
generated
vendored
@ -5,5 +5,5 @@ package otlptrace // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace"
|
||||
|
||||
// Version is the current release version of the OpenTelemetry OTLP trace exporter in use.
|
||||
func Version() string {
|
||||
return "1.33.0"
|
||||
return "1.35.0"
|
||||
}
|
||||
|
8
vendor/go.opentelemetry.io/otel/renovate.json
generated
vendored
8
vendor/go.opentelemetry.io/otel/renovate.json
generated
vendored
@ -1,7 +1,7 @@
|
||||
{
|
||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||
"extends": [
|
||||
"config:recommended"
|
||||
"config:best-practices"
|
||||
],
|
||||
"ignorePaths": [],
|
||||
"labels": ["Skip Changelog", "dependencies"],
|
||||
@ -15,10 +15,8 @@
|
||||
"enabled": true
|
||||
},
|
||||
{
|
||||
"matchFileNames": ["internal/tools/**"],
|
||||
"matchManagers": ["gomod"],
|
||||
"matchDepTypes": ["indirect"],
|
||||
"enabled": false
|
||||
"matchPackageNames": ["go.opentelemetry.io/build-tools/**"],
|
||||
"groupName": "build-tools"
|
||||
},
|
||||
{
|
||||
"matchPackageNames": ["google.golang.org/genproto/googleapis/**"],
|
||||
|
2
vendor/go.opentelemetry.io/otel/requirements.txt
generated
vendored
2
vendor/go.opentelemetry.io/otel/requirements.txt
generated
vendored
@ -1 +1 @@
|
||||
codespell==2.3.0
|
||||
codespell==2.4.1
|
||||
|
@ -48,7 +48,7 @@ type expoHistogramDataPoint[N int64 | float64] struct {
|
||||
zeroCount uint64
|
||||
}
|
||||
|
||||
func newExpoHistogramDataPoint[N int64 | float64](attrs attribute.Set, maxSize int, maxScale int32, noMinMax, noSum bool) *expoHistogramDataPoint[N] {
|
||||
func newExpoHistogramDataPoint[N int64 | float64](attrs attribute.Set, maxSize int, maxScale int32, noMinMax, noSum bool) *expoHistogramDataPoint[N] { // nolint:revive // we need this control flag
|
||||
f := math.MaxFloat64
|
||||
ma := N(f) // if N is int64, max will overflow to -9223372036854775808
|
||||
mi := N(-f)
|
||||
|
2
vendor/go.opentelemetry.io/otel/sdk/metric/version.go
generated
vendored
2
vendor/go.opentelemetry.io/otel/sdk/metric/version.go
generated
vendored
@ -5,5 +5,5 @@ package metric // import "go.opentelemetry.io/otel/sdk/metric"
|
||||
|
||||
// version is the current release version of the metric SDK in use.
|
||||
func version() string {
|
||||
return "1.33.0"
|
||||
return "1.35.0"
|
||||
}
|
||||
|
3
vendor/go.opentelemetry.io/otel/sdk/resource/os_release_darwin.go
generated
vendored
3
vendor/go.opentelemetry.io/otel/sdk/resource/os_release_darwin.go
generated
vendored
@ -5,6 +5,7 @@ package resource // import "go.opentelemetry.io/otel/sdk/resource"
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
@ -63,7 +64,7 @@ func parsePlistFile(file io.Reader) (map[string]string, error) {
|
||||
}
|
||||
|
||||
if len(v.Dict.Key) != len(v.Dict.String) {
|
||||
return nil, fmt.Errorf("the number of <key> and <string> elements doesn't match")
|
||||
return nil, errors.New("the number of <key> and <string> elements doesn't match")
|
||||
}
|
||||
|
||||
properties := make(map[string]string, len(v.Dict.Key))
|
||||
|
25
vendor/go.opentelemetry.io/otel/sdk/resource/resource.go
generated
vendored
25
vendor/go.opentelemetry.io/otel/sdk/resource/resource.go
generated
vendored
@ -21,11 +21,22 @@ import (
|
||||
// Resources should be passed and stored as pointers
|
||||
// (`*resource.Resource`). The `nil` value is equivalent to an empty
|
||||
// Resource.
|
||||
//
|
||||
// Note that the Go == operator compares not just the resource attributes but
|
||||
// also all other internals of the Resource type. Therefore, Resource values
|
||||
// should not be used as map or database keys. In general, the [Resource.Equal]
|
||||
// method should be used instead of direct comparison with ==, since that
|
||||
// method ensures the correct comparison of resource attributes, and the
|
||||
// [attribute.Distinct] returned from [Resource.Equivalent] should be used for
|
||||
// map and database keys instead.
|
||||
type Resource struct {
|
||||
attrs attribute.Set
|
||||
schemaURL string
|
||||
}
|
||||
|
||||
// Compile-time check that the Resource remains comparable.
|
||||
var _ map[Resource]struct{} = nil
|
||||
|
||||
var (
|
||||
defaultResource *Resource
|
||||
defaultResourceOnce sync.Once
|
||||
@ -137,15 +148,19 @@ func (r *Resource) Iter() attribute.Iterator {
|
||||
return r.attrs.Iter()
|
||||
}
|
||||
|
||||
// Equal returns true when a Resource is equivalent to this Resource.
|
||||
func (r *Resource) Equal(eq *Resource) bool {
|
||||
// Equal returns whether r and o represent the same resource. Two resources can
|
||||
// be equal even if they have different schema URLs.
|
||||
//
|
||||
// See the documentation on the [Resource] type for the pitfalls of using ==
|
||||
// with Resource values; most code should use Equal instead.
|
||||
func (r *Resource) Equal(o *Resource) bool {
|
||||
if r == nil {
|
||||
r = Empty()
|
||||
}
|
||||
if eq == nil {
|
||||
eq = Empty()
|
||||
if o == nil {
|
||||
o = Empty()
|
||||
}
|
||||
return r.Equivalent() == eq.Equivalent()
|
||||
return r.Equivalent() == o.Equivalent()
|
||||
}
|
||||
|
||||
// Merge creates a new [Resource] by merging a and b.
|
||||
|
3
vendor/go.opentelemetry.io/otel/sdk/trace/batch_span_processor.go
generated
vendored
3
vendor/go.opentelemetry.io/otel/sdk/trace/batch_span_processor.go
generated
vendored
@ -201,10 +201,9 @@ func (bsp *batchSpanProcessor) ForceFlush(ctx context.Context) error {
|
||||
}
|
||||
}
|
||||
|
||||
wait := make(chan error)
|
||||
wait := make(chan error, 1)
|
||||
go func() {
|
||||
wait <- bsp.exportSpans(ctx)
|
||||
close(wait)
|
||||
}()
|
||||
// Wait until the export is finished or the context is cancelled/timed out
|
||||
select {
|
||||
|
8
vendor/go.opentelemetry.io/otel/sdk/trace/sampling.go
generated
vendored
8
vendor/go.opentelemetry.io/otel/sdk/trace/sampling.go
generated
vendored
@ -47,12 +47,12 @@ const (
|
||||
// Drop will not record the span and all attributes/events will be dropped.
|
||||
Drop SamplingDecision = iota
|
||||
|
||||
// Record indicates the span's `IsRecording() == true`, but `Sampled` flag
|
||||
// *must not* be set.
|
||||
// RecordOnly indicates the span's IsRecording method returns true, but trace.FlagsSampled flag
|
||||
// must not be set.
|
||||
RecordOnly
|
||||
|
||||
// RecordAndSample has span's `IsRecording() == true` and `Sampled` flag
|
||||
// *must* be set.
|
||||
// RecordAndSample indicates the span's IsRecording method returns true and trace.FlagsSampled flag
|
||||
// must be set.
|
||||
RecordAndSample
|
||||
)
|
||||
|
||||
|
2
vendor/go.opentelemetry.io/otel/sdk/trace/simple_span_processor.go
generated
vendored
2
vendor/go.opentelemetry.io/otel/sdk/trace/simple_span_processor.go
generated
vendored
@ -58,7 +58,7 @@ func (ssp *simpleSpanProcessor) Shutdown(ctx context.Context) error {
|
||||
var err error
|
||||
ssp.stopOnce.Do(func() {
|
||||
stopFunc := func(exp SpanExporter) (<-chan error, func()) {
|
||||
done := make(chan error)
|
||||
done := make(chan error, 1)
|
||||
return done, func() { done <- exp.Shutdown(ctx) }
|
||||
}
|
||||
|
||||
|
2
vendor/go.opentelemetry.io/otel/sdk/version.go
generated
vendored
2
vendor/go.opentelemetry.io/otel/sdk/version.go
generated
vendored
@ -5,5 +5,5 @@ package sdk // import "go.opentelemetry.io/otel/sdk"
|
||||
|
||||
// Version is the current release version of the OpenTelemetry SDK in use.
|
||||
func Version() string {
|
||||
return "1.33.0"
|
||||
return "1.35.0"
|
||||
}
|
||||
|
3
vendor/go.opentelemetry.io/otel/semconv/v1.21.0/README.md
generated
vendored
3
vendor/go.opentelemetry.io/otel/semconv/v1.21.0/README.md
generated
vendored
@ -1,3 +0,0 @@
|
||||
# Semconv v1.21.0
|
||||
|
||||
[](https://pkg.go.dev/go.opentelemetry.io/otel/semconv/v1.21.0)
|
1866
vendor/go.opentelemetry.io/otel/semconv/v1.21.0/attribute_group.go
generated
vendored
1866
vendor/go.opentelemetry.io/otel/semconv/v1.21.0/attribute_group.go
generated
vendored
File diff suppressed because it is too large
Load Diff
9
vendor/go.opentelemetry.io/otel/semconv/v1.21.0/doc.go
generated
vendored
9
vendor/go.opentelemetry.io/otel/semconv/v1.21.0/doc.go
generated
vendored
@ -1,9 +0,0 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Package semconv implements OpenTelemetry semantic conventions.
|
||||
//
|
||||
// OpenTelemetry semantic conventions are agreed standardized naming
|
||||
// patterns for OpenTelemetry things. This package represents the v1.21.0
|
||||
// version of the OpenTelemetry semantic conventions.
|
||||
package semconv // import "go.opentelemetry.io/otel/semconv/v1.21.0"
|
188
vendor/go.opentelemetry.io/otel/semconv/v1.21.0/event.go
generated
vendored
188
vendor/go.opentelemetry.io/otel/semconv/v1.21.0/event.go
generated
vendored
@ -1,188 +0,0 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Code generated from semantic convention specification. DO NOT EDIT.
|
||||
|
||||
package semconv // import "go.opentelemetry.io/otel/semconv/v1.21.0"
|
||||
|
||||
import "go.opentelemetry.io/otel/attribute"
|
||||
|
||||
// This semantic convention defines the attributes used to represent a feature
|
||||
// flag evaluation as an event.
|
||||
const (
|
||||
// FeatureFlagKeyKey is the attribute Key conforming to the
|
||||
// "feature_flag.key" semantic conventions. It represents the unique
|
||||
// identifier of the feature flag.
|
||||
//
|
||||
// Type: string
|
||||
// RequirementLevel: Required
|
||||
// Stability: stable
|
||||
// Examples: 'logo-color'
|
||||
FeatureFlagKeyKey = attribute.Key("feature_flag.key")
|
||||
|
||||
// FeatureFlagProviderNameKey is the attribute Key conforming to the
|
||||
// "feature_flag.provider_name" semantic conventions. It represents the
|
||||
// name of the service provider that performs the flag evaluation.
|
||||
//
|
||||
// Type: string
|
||||
// RequirementLevel: Recommended
|
||||
// Stability: stable
|
||||
// Examples: 'Flag Manager'
|
||||
FeatureFlagProviderNameKey = attribute.Key("feature_flag.provider_name")
|
||||
|
||||
// FeatureFlagVariantKey is the attribute Key conforming to the
|
||||
// "feature_flag.variant" semantic conventions. It represents the sHOULD be
|
||||
// a semantic identifier for a value. If one is unavailable, a stringified
|
||||
// version of the value can be used.
|
||||
//
|
||||
// Type: string
|
||||
// RequirementLevel: Recommended
|
||||
// Stability: stable
|
||||
// Examples: 'red', 'true', 'on'
|
||||
// Note: A semantic identifier, commonly referred to as a variant, provides
|
||||
// a means
|
||||
// for referring to a value without including the value itself. This can
|
||||
// provide additional context for understanding the meaning behind a value.
|
||||
// For example, the variant `red` maybe be used for the value `#c05543`.
|
||||
//
|
||||
// A stringified version of the value can be used in situations where a
|
||||
// semantic identifier is unavailable. String representation of the value
|
||||
// should be determined by the implementer.
|
||||
FeatureFlagVariantKey = attribute.Key("feature_flag.variant")
|
||||
)
|
||||
|
||||
// FeatureFlagKey returns an attribute KeyValue conforming to the
|
||||
// "feature_flag.key" semantic conventions. It represents the unique identifier
|
||||
// of the feature flag.
|
||||
func FeatureFlagKey(val string) attribute.KeyValue {
|
||||
return FeatureFlagKeyKey.String(val)
|
||||
}
|
||||
|
||||
// FeatureFlagProviderName returns an attribute KeyValue conforming to the
|
||||
// "feature_flag.provider_name" semantic conventions. It represents the name of
|
||||
// the service provider that performs the flag evaluation.
|
||||
func FeatureFlagProviderName(val string) attribute.KeyValue {
|
||||
return FeatureFlagProviderNameKey.String(val)
|
||||
}
|
||||
|
||||
// FeatureFlagVariant returns an attribute KeyValue conforming to the
|
||||
// "feature_flag.variant" semantic conventions. It represents the sHOULD be a
|
||||
// semantic identifier for a value. If one is unavailable, a stringified
|
||||
// version of the value can be used.
|
||||
func FeatureFlagVariant(val string) attribute.KeyValue {
|
||||
return FeatureFlagVariantKey.String(val)
|
||||
}
|
||||
|
||||
// RPC received/sent message.
|
||||
const (
|
||||
// MessageTypeKey is the attribute Key conforming to the "message.type"
|
||||
// semantic conventions. It represents the whether this is a received or
|
||||
// sent message.
|
||||
//
|
||||
// Type: Enum
|
||||
// RequirementLevel: Optional
|
||||
// Stability: stable
|
||||
MessageTypeKey = attribute.Key("message.type")
|
||||
|
||||
// MessageIDKey is the attribute Key conforming to the "message.id"
|
||||
// semantic conventions. It represents the mUST be calculated as two
|
||||
// different counters starting from `1` one for sent messages and one for
|
||||
// received message.
|
||||
//
|
||||
// Type: int
|
||||
// RequirementLevel: Optional
|
||||
// Stability: stable
|
||||
// Note: This way we guarantee that the values will be consistent between
|
||||
// different implementations.
|
||||
MessageIDKey = attribute.Key("message.id")
|
||||
|
||||
// MessageCompressedSizeKey is the attribute Key conforming to the
|
||||
// "message.compressed_size" semantic conventions. It represents the
|
||||
// compressed size of the message in bytes.
|
||||
//
|
||||
// Type: int
|
||||
// RequirementLevel: Optional
|
||||
// Stability: stable
|
||||
MessageCompressedSizeKey = attribute.Key("message.compressed_size")
|
||||
|
||||
// MessageUncompressedSizeKey is the attribute Key conforming to the
|
||||
// "message.uncompressed_size" semantic conventions. It represents the
|
||||
// uncompressed size of the message in bytes.
|
||||
//
|
||||
// Type: int
|
||||
// RequirementLevel: Optional
|
||||
// Stability: stable
|
||||
MessageUncompressedSizeKey = attribute.Key("message.uncompressed_size")
|
||||
)
|
||||
|
||||
var (
|
||||
// sent
|
||||
MessageTypeSent = MessageTypeKey.String("SENT")
|
||||
// received
|
||||
MessageTypeReceived = MessageTypeKey.String("RECEIVED")
|
||||
)
|
||||
|
||||
// MessageID returns an attribute KeyValue conforming to the "message.id"
|
||||
// semantic conventions. It represents the mUST be calculated as two different
|
||||
// counters starting from `1` one for sent messages and one for received
|
||||
// message.
|
||||
func MessageID(val int) attribute.KeyValue {
|
||||
return MessageIDKey.Int(val)
|
||||
}
|
||||
|
||||
// MessageCompressedSize returns an attribute KeyValue conforming to the
|
||||
// "message.compressed_size" semantic conventions. It represents the compressed
|
||||
// size of the message in bytes.
|
||||
func MessageCompressedSize(val int) attribute.KeyValue {
|
||||
return MessageCompressedSizeKey.Int(val)
|
||||
}
|
||||
|
||||
// MessageUncompressedSize returns an attribute KeyValue conforming to the
|
||||
// "message.uncompressed_size" semantic conventions. It represents the
|
||||
// uncompressed size of the message in bytes.
|
||||
func MessageUncompressedSize(val int) attribute.KeyValue {
|
||||
return MessageUncompressedSizeKey.Int(val)
|
||||
}
|
||||
|
||||
// The attributes used to report a single exception associated with a span.
|
||||
const (
|
||||
// ExceptionEscapedKey is the attribute Key conforming to the
|
||||
// "exception.escaped" semantic conventions. It represents the sHOULD be
|
||||
// set to true if the exception event is recorded at a point where it is
|
||||
// known that the exception is escaping the scope of the span.
|
||||
//
|
||||
// Type: boolean
|
||||
// RequirementLevel: Optional
|
||||
// Stability: stable
|
||||
// Note: An exception is considered to have escaped (or left) the scope of
|
||||
// a span,
|
||||
// if that span is ended while the exception is still logically "in
|
||||
// flight".
|
||||
// This may be actually "in flight" in some languages (e.g. if the
|
||||
// exception
|
||||
// is passed to a Context manager's `__exit__` method in Python) but will
|
||||
// usually be caught at the point of recording the exception in most
|
||||
// languages.
|
||||
//
|
||||
// It is usually not possible to determine at the point where an exception
|
||||
// is thrown
|
||||
// whether it will escape the scope of a span.
|
||||
// However, it is trivial to know that an exception
|
||||
// will escape, if one checks for an active exception just before ending
|
||||
// the span,
|
||||
// as done in the [example above](#recording-an-exception).
|
||||
//
|
||||
// It follows that an exception may still escape the scope of the span
|
||||
// even if the `exception.escaped` attribute was not set or set to false,
|
||||
// since the event might have been recorded at a time where it was not
|
||||
// clear whether the exception will escape.
|
||||
ExceptionEscapedKey = attribute.Key("exception.escaped")
|
||||
)
|
||||
|
||||
// ExceptionEscaped returns an attribute KeyValue conforming to the
|
||||
// "exception.escaped" semantic conventions. It represents the sHOULD be set to
|
||||
// true if the exception event is recorded at a point where it is known that
|
||||
// the exception is escaping the scope of the span.
|
||||
func ExceptionEscaped(val bool) attribute.KeyValue {
|
||||
return ExceptionEscapedKey.Bool(val)
|
||||
}
|
9
vendor/go.opentelemetry.io/otel/semconv/v1.21.0/exception.go
generated
vendored
9
vendor/go.opentelemetry.io/otel/semconv/v1.21.0/exception.go
generated
vendored
@ -1,9 +0,0 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package semconv // import "go.opentelemetry.io/otel/semconv/v1.21.0"
|
||||
|
||||
const (
|
||||
// ExceptionEventName is the name of the Span event representing an exception.
|
||||
ExceptionEventName = "exception"
|
||||
)
|
2299
vendor/go.opentelemetry.io/otel/semconv/v1.21.0/resource.go
generated
vendored
2299
vendor/go.opentelemetry.io/otel/semconv/v1.21.0/resource.go
generated
vendored
File diff suppressed because it is too large
Load Diff
9
vendor/go.opentelemetry.io/otel/semconv/v1.21.0/schema.go
generated
vendored
9
vendor/go.opentelemetry.io/otel/semconv/v1.21.0/schema.go
generated
vendored
@ -1,9 +0,0 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package semconv // import "go.opentelemetry.io/otel/semconv/v1.21.0"
|
||||
|
||||
// SchemaURL is the schema URL that matches the version of the semantic conventions
|
||||
// that this package defines. Semconv packages starting from v1.4.0 must declare
|
||||
// non-empty schema URL in the form https://opentelemetry.io/schemas/<version>
|
||||
const SchemaURL = "https://opentelemetry.io/schemas/1.21.0"
|
2484
vendor/go.opentelemetry.io/otel/semconv/v1.21.0/trace.go
generated
vendored
2484
vendor/go.opentelemetry.io/otel/semconv/v1.21.0/trace.go
generated
vendored
File diff suppressed because it is too large
Load Diff
661
vendor/go.opentelemetry.io/otel/trace/auto.go
generated
vendored
Normal file
661
vendor/go.opentelemetry.io/otel/trace/auto.go
generated
vendored
Normal file
@ -0,0 +1,661 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package trace // import "go.opentelemetry.io/otel/trace"
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math"
|
||||
"os"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/codes"
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.26.0"
|
||||
"go.opentelemetry.io/otel/trace/embedded"
|
||||
"go.opentelemetry.io/otel/trace/internal/telemetry"
|
||||
)
|
||||
|
||||
// newAutoTracerProvider returns an auto-instrumentable [trace.TracerProvider].
|
||||
// If an [go.opentelemetry.io/auto.Instrumentation] is configured to instrument
|
||||
// the process using the returned TracerProvider, all of the telemetry it
|
||||
// produces will be processed and handled by that Instrumentation. By default,
|
||||
// if no Instrumentation instruments the TracerProvider it will not generate
|
||||
// any trace telemetry.
|
||||
func newAutoTracerProvider() TracerProvider { return tracerProviderInstance }
|
||||
|
||||
var tracerProviderInstance = new(autoTracerProvider)
|
||||
|
||||
type autoTracerProvider struct{ embedded.TracerProvider }
|
||||
|
||||
var _ TracerProvider = autoTracerProvider{}
|
||||
|
||||
func (p autoTracerProvider) Tracer(name string, opts ...TracerOption) Tracer {
|
||||
cfg := NewTracerConfig(opts...)
|
||||
return autoTracer{
|
||||
name: name,
|
||||
version: cfg.InstrumentationVersion(),
|
||||
schemaURL: cfg.SchemaURL(),
|
||||
}
|
||||
}
|
||||
|
||||
type autoTracer struct {
|
||||
embedded.Tracer
|
||||
|
||||
name, schemaURL, version string
|
||||
}
|
||||
|
||||
var _ Tracer = autoTracer{}
|
||||
|
||||
func (t autoTracer) Start(ctx context.Context, name string, opts ...SpanStartOption) (context.Context, Span) {
|
||||
var psc SpanContext
|
||||
sampled := true
|
||||
span := new(autoSpan)
|
||||
|
||||
// Ask eBPF for sampling decision and span context info.
|
||||
t.start(ctx, span, &psc, &sampled, &span.spanContext)
|
||||
|
||||
span.sampled.Store(sampled)
|
||||
|
||||
ctx = ContextWithSpan(ctx, span)
|
||||
|
||||
if sampled {
|
||||
// Only build traces if sampled.
|
||||
cfg := NewSpanStartConfig(opts...)
|
||||
span.traces, span.span = t.traces(name, cfg, span.spanContext, psc)
|
||||
}
|
||||
|
||||
return ctx, span
|
||||
}
|
||||
|
||||
// Expected to be implemented in eBPF.
|
||||
//
|
||||
//go:noinline
|
||||
func (t *autoTracer) start(
|
||||
ctx context.Context,
|
||||
spanPtr *autoSpan,
|
||||
psc *SpanContext,
|
||||
sampled *bool,
|
||||
sc *SpanContext,
|
||||
) {
|
||||
start(ctx, spanPtr, psc, sampled, sc)
|
||||
}
|
||||
|
||||
// start is used for testing.
|
||||
var start = func(context.Context, *autoSpan, *SpanContext, *bool, *SpanContext) {}
|
||||
|
||||
func (t autoTracer) traces(name string, cfg SpanConfig, sc, psc SpanContext) (*telemetry.Traces, *telemetry.Span) {
|
||||
span := &telemetry.Span{
|
||||
TraceID: telemetry.TraceID(sc.TraceID()),
|
||||
SpanID: telemetry.SpanID(sc.SpanID()),
|
||||
Flags: uint32(sc.TraceFlags()),
|
||||
TraceState: sc.TraceState().String(),
|
||||
ParentSpanID: telemetry.SpanID(psc.SpanID()),
|
||||
Name: name,
|
||||
Kind: spanKind(cfg.SpanKind()),
|
||||
}
|
||||
|
||||
span.Attrs, span.DroppedAttrs = convCappedAttrs(maxSpan.Attrs, cfg.Attributes())
|
||||
|
||||
links := cfg.Links()
|
||||
if limit := maxSpan.Links; limit == 0 {
|
||||
n := int64(len(links))
|
||||
if n > 0 {
|
||||
span.DroppedLinks = uint32(min(n, math.MaxUint32)) // nolint: gosec // Bounds checked.
|
||||
}
|
||||
} else {
|
||||
if limit > 0 {
|
||||
n := int64(max(len(links)-limit, 0))
|
||||
span.DroppedLinks = uint32(min(n, math.MaxUint32)) // nolint: gosec // Bounds checked.
|
||||
links = links[n:]
|
||||
}
|
||||
span.Links = convLinks(links)
|
||||
}
|
||||
|
||||
if t := cfg.Timestamp(); !t.IsZero() {
|
||||
span.StartTime = cfg.Timestamp()
|
||||
} else {
|
||||
span.StartTime = time.Now()
|
||||
}
|
||||
|
||||
return &telemetry.Traces{
|
||||
ResourceSpans: []*telemetry.ResourceSpans{
|
||||
{
|
||||
ScopeSpans: []*telemetry.ScopeSpans{
|
||||
{
|
||||
Scope: &telemetry.Scope{
|
||||
Name: t.name,
|
||||
Version: t.version,
|
||||
},
|
||||
Spans: []*telemetry.Span{span},
|
||||
SchemaURL: t.schemaURL,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}, span
|
||||
}
|
||||
|
||||
func spanKind(kind SpanKind) telemetry.SpanKind {
|
||||
switch kind {
|
||||
case SpanKindInternal:
|
||||
return telemetry.SpanKindInternal
|
||||
case SpanKindServer:
|
||||
return telemetry.SpanKindServer
|
||||
case SpanKindClient:
|
||||
return telemetry.SpanKindClient
|
||||
case SpanKindProducer:
|
||||
return telemetry.SpanKindProducer
|
||||
case SpanKindConsumer:
|
||||
return telemetry.SpanKindConsumer
|
||||
}
|
||||
return telemetry.SpanKind(0) // undefined.
|
||||
}
|
||||
|
||||
type autoSpan struct {
|
||||
embedded.Span
|
||||
|
||||
spanContext SpanContext
|
||||
sampled atomic.Bool
|
||||
|
||||
mu sync.Mutex
|
||||
traces *telemetry.Traces
|
||||
span *telemetry.Span
|
||||
}
|
||||
|
||||
func (s *autoSpan) SpanContext() SpanContext {
|
||||
if s == nil {
|
||||
return SpanContext{}
|
||||
}
|
||||
// s.spanContext is immutable, do not acquire lock s.mu.
|
||||
return s.spanContext
|
||||
}
|
||||
|
||||
func (s *autoSpan) IsRecording() bool {
|
||||
if s == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return s.sampled.Load()
|
||||
}
|
||||
|
||||
func (s *autoSpan) SetStatus(c codes.Code, msg string) {
|
||||
if s == nil || !s.sampled.Load() {
|
||||
return
|
||||
}
|
||||
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
if s.span.Status == nil {
|
||||
s.span.Status = new(telemetry.Status)
|
||||
}
|
||||
|
||||
s.span.Status.Message = msg
|
||||
|
||||
switch c {
|
||||
case codes.Unset:
|
||||
s.span.Status.Code = telemetry.StatusCodeUnset
|
||||
case codes.Error:
|
||||
s.span.Status.Code = telemetry.StatusCodeError
|
||||
case codes.Ok:
|
||||
s.span.Status.Code = telemetry.StatusCodeOK
|
||||
}
|
||||
}
|
||||
|
||||
func (s *autoSpan) SetAttributes(attrs ...attribute.KeyValue) {
|
||||
if s == nil || !s.sampled.Load() {
|
||||
return
|
||||
}
|
||||
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
limit := maxSpan.Attrs
|
||||
if limit == 0 {
|
||||
// No attributes allowed.
|
||||
n := int64(len(attrs))
|
||||
if n > 0 {
|
||||
s.span.DroppedAttrs += uint32(min(n, math.MaxUint32)) // nolint: gosec // Bounds checked.
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
m := make(map[string]int)
|
||||
for i, a := range s.span.Attrs {
|
||||
m[a.Key] = i
|
||||
}
|
||||
|
||||
for _, a := range attrs {
|
||||
val := convAttrValue(a.Value)
|
||||
if val.Empty() {
|
||||
s.span.DroppedAttrs++
|
||||
continue
|
||||
}
|
||||
|
||||
if idx, ok := m[string(a.Key)]; ok {
|
||||
s.span.Attrs[idx] = telemetry.Attr{
|
||||
Key: string(a.Key),
|
||||
Value: val,
|
||||
}
|
||||
} else if limit < 0 || len(s.span.Attrs) < limit {
|
||||
s.span.Attrs = append(s.span.Attrs, telemetry.Attr{
|
||||
Key: string(a.Key),
|
||||
Value: val,
|
||||
})
|
||||
m[string(a.Key)] = len(s.span.Attrs) - 1
|
||||
} else {
|
||||
s.span.DroppedAttrs++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// convCappedAttrs converts up to limit attrs into a []telemetry.Attr. The
|
||||
// number of dropped attributes is also returned.
|
||||
func convCappedAttrs(limit int, attrs []attribute.KeyValue) ([]telemetry.Attr, uint32) {
|
||||
n := len(attrs)
|
||||
if limit == 0 {
|
||||
var out uint32
|
||||
if n > 0 {
|
||||
out = uint32(min(int64(n), math.MaxUint32)) // nolint: gosec // Bounds checked.
|
||||
}
|
||||
return nil, out
|
||||
}
|
||||
|
||||
if limit < 0 {
|
||||
// Unlimited.
|
||||
return convAttrs(attrs), 0
|
||||
}
|
||||
|
||||
if n < 0 {
|
||||
n = 0
|
||||
}
|
||||
|
||||
limit = min(n, limit)
|
||||
return convAttrs(attrs[:limit]), uint32(n - limit) // nolint: gosec // Bounds checked.
|
||||
}
|
||||
|
||||
func convAttrs(attrs []attribute.KeyValue) []telemetry.Attr {
|
||||
if len(attrs) == 0 {
|
||||
// Avoid allocations if not necessary.
|
||||
return nil
|
||||
}
|
||||
|
||||
out := make([]telemetry.Attr, 0, len(attrs))
|
||||
for _, attr := range attrs {
|
||||
key := string(attr.Key)
|
||||
val := convAttrValue(attr.Value)
|
||||
if val.Empty() {
|
||||
continue
|
||||
}
|
||||
out = append(out, telemetry.Attr{Key: key, Value: val})
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func convAttrValue(value attribute.Value) telemetry.Value {
|
||||
switch value.Type() {
|
||||
case attribute.BOOL:
|
||||
return telemetry.BoolValue(value.AsBool())
|
||||
case attribute.INT64:
|
||||
return telemetry.Int64Value(value.AsInt64())
|
||||
case attribute.FLOAT64:
|
||||
return telemetry.Float64Value(value.AsFloat64())
|
||||
case attribute.STRING:
|
||||
v := truncate(maxSpan.AttrValueLen, value.AsString())
|
||||
return telemetry.StringValue(v)
|
||||
case attribute.BOOLSLICE:
|
||||
slice := value.AsBoolSlice()
|
||||
out := make([]telemetry.Value, 0, len(slice))
|
||||
for _, v := range slice {
|
||||
out = append(out, telemetry.BoolValue(v))
|
||||
}
|
||||
return telemetry.SliceValue(out...)
|
||||
case attribute.INT64SLICE:
|
||||
slice := value.AsInt64Slice()
|
||||
out := make([]telemetry.Value, 0, len(slice))
|
||||
for _, v := range slice {
|
||||
out = append(out, telemetry.Int64Value(v))
|
||||
}
|
||||
return telemetry.SliceValue(out...)
|
||||
case attribute.FLOAT64SLICE:
|
||||
slice := value.AsFloat64Slice()
|
||||
out := make([]telemetry.Value, 0, len(slice))
|
||||
for _, v := range slice {
|
||||
out = append(out, telemetry.Float64Value(v))
|
||||
}
|
||||
return telemetry.SliceValue(out...)
|
||||
case attribute.STRINGSLICE:
|
||||
slice := value.AsStringSlice()
|
||||
out := make([]telemetry.Value, 0, len(slice))
|
||||
for _, v := range slice {
|
||||
v = truncate(maxSpan.AttrValueLen, v)
|
||||
out = append(out, telemetry.StringValue(v))
|
||||
}
|
||||
return telemetry.SliceValue(out...)
|
||||
}
|
||||
return telemetry.Value{}
|
||||
}
|
||||
|
||||
// truncate returns a truncated version of s such that it contains less than
|
||||
// the limit number of characters. Truncation is applied by returning the limit
|
||||
// number of valid characters contained in s.
|
||||
//
|
||||
// If limit is negative, it returns the original string.
|
||||
//
|
||||
// UTF-8 is supported. When truncating, all invalid characters are dropped
|
||||
// before applying truncation.
|
||||
//
|
||||
// If s already contains less than the limit number of bytes, it is returned
|
||||
// unchanged. No invalid characters are removed.
|
||||
func truncate(limit int, s string) string {
|
||||
// This prioritize performance in the following order based on the most
|
||||
// common expected use-cases.
|
||||
//
|
||||
// - Short values less than the default limit (128).
|
||||
// - Strings with valid encodings that exceed the limit.
|
||||
// - No limit.
|
||||
// - Strings with invalid encodings that exceed the limit.
|
||||
if limit < 0 || len(s) <= limit {
|
||||
return s
|
||||
}
|
||||
|
||||
// Optimistically, assume all valid UTF-8.
|
||||
var b strings.Builder
|
||||
count := 0
|
||||
for i, c := range s {
|
||||
if c != utf8.RuneError {
|
||||
count++
|
||||
if count > limit {
|
||||
return s[:i]
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
_, size := utf8.DecodeRuneInString(s[i:])
|
||||
if size == 1 {
|
||||
// Invalid encoding.
|
||||
b.Grow(len(s) - 1)
|
||||
_, _ = b.WriteString(s[:i])
|
||||
s = s[i:]
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// Fast-path, no invalid input.
|
||||
if b.Cap() == 0 {
|
||||
return s
|
||||
}
|
||||
|
||||
// Truncate while validating UTF-8.
|
||||
for i := 0; i < len(s) && count < limit; {
|
||||
c := s[i]
|
||||
if c < utf8.RuneSelf {
|
||||
// Optimization for single byte runes (common case).
|
||||
_ = b.WriteByte(c)
|
||||
i++
|
||||
count++
|
||||
continue
|
||||
}
|
||||
|
||||
_, size := utf8.DecodeRuneInString(s[i:])
|
||||
if size == 1 {
|
||||
// We checked for all 1-byte runes above, this is a RuneError.
|
||||
i++
|
||||
continue
|
||||
}
|
||||
|
||||
_, _ = b.WriteString(s[i : i+size])
|
||||
i += size
|
||||
count++
|
||||
}
|
||||
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func (s *autoSpan) End(opts ...SpanEndOption) {
|
||||
if s == nil || !s.sampled.Swap(false) {
|
||||
return
|
||||
}
|
||||
|
||||
// s.end exists so the lock (s.mu) is not held while s.ended is called.
|
||||
s.ended(s.end(opts))
|
||||
}
|
||||
|
||||
func (s *autoSpan) end(opts []SpanEndOption) []byte {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
cfg := NewSpanEndConfig(opts...)
|
||||
if t := cfg.Timestamp(); !t.IsZero() {
|
||||
s.span.EndTime = cfg.Timestamp()
|
||||
} else {
|
||||
s.span.EndTime = time.Now()
|
||||
}
|
||||
|
||||
b, _ := json.Marshal(s.traces) // TODO: do not ignore this error.
|
||||
return b
|
||||
}
|
||||
|
||||
// Expected to be implemented in eBPF.
|
||||
//
|
||||
//go:noinline
|
||||
func (*autoSpan) ended(buf []byte) { ended(buf) }
|
||||
|
||||
// ended is used for testing.
|
||||
var ended = func([]byte) {}
|
||||
|
||||
func (s *autoSpan) RecordError(err error, opts ...EventOption) {
|
||||
if s == nil || err == nil || !s.sampled.Load() {
|
||||
return
|
||||
}
|
||||
|
||||
cfg := NewEventConfig(opts...)
|
||||
|
||||
attrs := cfg.Attributes()
|
||||
attrs = append(attrs,
|
||||
semconv.ExceptionType(typeStr(err)),
|
||||
semconv.ExceptionMessage(err.Error()),
|
||||
)
|
||||
if cfg.StackTrace() {
|
||||
buf := make([]byte, 2048)
|
||||
n := runtime.Stack(buf, false)
|
||||
attrs = append(attrs, semconv.ExceptionStacktrace(string(buf[0:n])))
|
||||
}
|
||||
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
s.addEvent(semconv.ExceptionEventName, cfg.Timestamp(), attrs)
|
||||
}
|
||||
|
||||
func typeStr(i any) string {
|
||||
t := reflect.TypeOf(i)
|
||||
if t.PkgPath() == "" && t.Name() == "" {
|
||||
// Likely a builtin type.
|
||||
return t.String()
|
||||
}
|
||||
return fmt.Sprintf("%s.%s", t.PkgPath(), t.Name())
|
||||
}
|
||||
|
||||
func (s *autoSpan) AddEvent(name string, opts ...EventOption) {
|
||||
if s == nil || !s.sampled.Load() {
|
||||
return
|
||||
}
|
||||
|
||||
cfg := NewEventConfig(opts...)
|
||||
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
s.addEvent(name, cfg.Timestamp(), cfg.Attributes())
|
||||
}
|
||||
|
||||
// addEvent adds an event with name and attrs at tStamp to the span. The span
|
||||
// lock (s.mu) needs to be held by the caller.
|
||||
func (s *autoSpan) addEvent(name string, tStamp time.Time, attrs []attribute.KeyValue) {
|
||||
limit := maxSpan.Events
|
||||
|
||||
if limit == 0 {
|
||||
s.span.DroppedEvents++
|
||||
return
|
||||
}
|
||||
|
||||
if limit > 0 && len(s.span.Events) == limit {
|
||||
// Drop head while avoiding allocation of more capacity.
|
||||
copy(s.span.Events[:limit-1], s.span.Events[1:])
|
||||
s.span.Events = s.span.Events[:limit-1]
|
||||
s.span.DroppedEvents++
|
||||
}
|
||||
|
||||
e := &telemetry.SpanEvent{Time: tStamp, Name: name}
|
||||
e.Attrs, e.DroppedAttrs = convCappedAttrs(maxSpan.EventAttrs, attrs)
|
||||
|
||||
s.span.Events = append(s.span.Events, e)
|
||||
}
|
||||
|
||||
func (s *autoSpan) AddLink(link Link) {
|
||||
if s == nil || !s.sampled.Load() {
|
||||
return
|
||||
}
|
||||
|
||||
l := maxSpan.Links
|
||||
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
if l == 0 {
|
||||
s.span.DroppedLinks++
|
||||
return
|
||||
}
|
||||
|
||||
if l > 0 && len(s.span.Links) == l {
|
||||
// Drop head while avoiding allocation of more capacity.
|
||||
copy(s.span.Links[:l-1], s.span.Links[1:])
|
||||
s.span.Links = s.span.Links[:l-1]
|
||||
s.span.DroppedLinks++
|
||||
}
|
||||
|
||||
s.span.Links = append(s.span.Links, convLink(link))
|
||||
}
|
||||
|
||||
func convLinks(links []Link) []*telemetry.SpanLink {
|
||||
out := make([]*telemetry.SpanLink, 0, len(links))
|
||||
for _, link := range links {
|
||||
out = append(out, convLink(link))
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func convLink(link Link) *telemetry.SpanLink {
|
||||
l := &telemetry.SpanLink{
|
||||
TraceID: telemetry.TraceID(link.SpanContext.TraceID()),
|
||||
SpanID: telemetry.SpanID(link.SpanContext.SpanID()),
|
||||
TraceState: link.SpanContext.TraceState().String(),
|
||||
Flags: uint32(link.SpanContext.TraceFlags()),
|
||||
}
|
||||
l.Attrs, l.DroppedAttrs = convCappedAttrs(maxSpan.LinkAttrs, link.Attributes)
|
||||
|
||||
return l
|
||||
}
|
||||
|
||||
func (s *autoSpan) SetName(name string) {
|
||||
if s == nil || !s.sampled.Load() {
|
||||
return
|
||||
}
|
||||
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
s.span.Name = name
|
||||
}
|
||||
|
||||
func (*autoSpan) TracerProvider() TracerProvider { return newAutoTracerProvider() }
|
||||
|
||||
// maxSpan are the span limits resolved during startup.
|
||||
var maxSpan = newSpanLimits()
|
||||
|
||||
type spanLimits struct {
|
||||
// Attrs is the number of allowed attributes for a span.
|
||||
//
|
||||
// This is resolved from the environment variable value for the
|
||||
// OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT key if it exists. Otherwise, the
|
||||
// environment variable value for OTEL_ATTRIBUTE_COUNT_LIMIT, or 128 if
|
||||
// that is not set, is used.
|
||||
Attrs int
|
||||
// AttrValueLen is the maximum attribute value length allowed for a span.
|
||||
//
|
||||
// This is resolved from the environment variable value for the
|
||||
// OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT key if it exists. Otherwise, the
|
||||
// environment variable value for OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT, or -1
|
||||
// if that is not set, is used.
|
||||
AttrValueLen int
|
||||
// Events is the number of allowed events for a span.
|
||||
//
|
||||
// This is resolved from the environment variable value for the
|
||||
// OTEL_SPAN_EVENT_COUNT_LIMIT key, or 128 is used if that is not set.
|
||||
Events int
|
||||
// EventAttrs is the number of allowed attributes for a span event.
|
||||
//
|
||||
// The is resolved from the environment variable value for the
|
||||
// OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT key, or 128 is used if that is not set.
|
||||
EventAttrs int
|
||||
// Links is the number of allowed Links for a span.
|
||||
//
|
||||
// This is resolved from the environment variable value for the
|
||||
// OTEL_SPAN_LINK_COUNT_LIMIT, or 128 is used if that is not set.
|
||||
Links int
|
||||
// LinkAttrs is the number of allowed attributes for a span link.
|
||||
//
|
||||
// This is resolved from the environment variable value for the
|
||||
// OTEL_LINK_ATTRIBUTE_COUNT_LIMIT, or 128 is used if that is not set.
|
||||
LinkAttrs int
|
||||
}
|
||||
|
||||
func newSpanLimits() spanLimits {
|
||||
return spanLimits{
|
||||
Attrs: firstEnv(
|
||||
128,
|
||||
"OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT",
|
||||
"OTEL_ATTRIBUTE_COUNT_LIMIT",
|
||||
),
|
||||
AttrValueLen: firstEnv(
|
||||
-1, // Unlimited.
|
||||
"OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT",
|
||||
"OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT",
|
||||
),
|
||||
Events: firstEnv(128, "OTEL_SPAN_EVENT_COUNT_LIMIT"),
|
||||
EventAttrs: firstEnv(128, "OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT"),
|
||||
Links: firstEnv(128, "OTEL_SPAN_LINK_COUNT_LIMIT"),
|
||||
LinkAttrs: firstEnv(128, "OTEL_LINK_ATTRIBUTE_COUNT_LIMIT"),
|
||||
}
|
||||
}
|
||||
|
||||
// firstEnv returns the parsed integer value of the first matching environment
|
||||
// variable from keys. The defaultVal is returned if the value is not an
|
||||
// integer or no match is found.
|
||||
func firstEnv(defaultVal int, keys ...string) int {
|
||||
for _, key := range keys {
|
||||
strV := os.Getenv(key)
|
||||
if strV == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
v, err := strconv.Atoi(strV)
|
||||
if err == nil {
|
||||
return v
|
||||
}
|
||||
// Ignore invalid environment variable.
|
||||
}
|
||||
|
||||
return defaultVal
|
||||
}
|
58
vendor/go.opentelemetry.io/otel/trace/internal/telemetry/attr.go
generated
vendored
Normal file
58
vendor/go.opentelemetry.io/otel/trace/internal/telemetry/attr.go
generated
vendored
Normal file
@ -0,0 +1,58 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package telemetry // import "go.opentelemetry.io/otel/trace/internal/telemetry"
|
||||
|
||||
// Attr is a key-value pair.
|
||||
type Attr struct {
|
||||
Key string `json:"key,omitempty"`
|
||||
Value Value `json:"value,omitempty"`
|
||||
}
|
||||
|
||||
// String returns an Attr for a string value.
|
||||
func String(key, value string) Attr {
|
||||
return Attr{key, StringValue(value)}
|
||||
}
|
||||
|
||||
// Int64 returns an Attr for an int64 value.
|
||||
func Int64(key string, value int64) Attr {
|
||||
return Attr{key, Int64Value(value)}
|
||||
}
|
||||
|
||||
// Int returns an Attr for an int value.
|
||||
func Int(key string, value int) Attr {
|
||||
return Int64(key, int64(value))
|
||||
}
|
||||
|
||||
// Float64 returns an Attr for a float64 value.
|
||||
func Float64(key string, value float64) Attr {
|
||||
return Attr{key, Float64Value(value)}
|
||||
}
|
||||
|
||||
// Bool returns an Attr for a bool value.
|
||||
func Bool(key string, value bool) Attr {
|
||||
return Attr{key, BoolValue(value)}
|
||||
}
|
||||
|
||||
// Bytes returns an Attr for a []byte value.
|
||||
// The passed slice must not be changed after it is passed.
|
||||
func Bytes(key string, value []byte) Attr {
|
||||
return Attr{key, BytesValue(value)}
|
||||
}
|
||||
|
||||
// Slice returns an Attr for a []Value value.
|
||||
// The passed slice must not be changed after it is passed.
|
||||
func Slice(key string, value ...Value) Attr {
|
||||
return Attr{key, SliceValue(value...)}
|
||||
}
|
||||
|
||||
// Map returns an Attr for a map value.
|
||||
// The passed slice must not be changed after it is passed.
|
||||
func Map(key string, value ...Attr) Attr {
|
||||
return Attr{key, MapValue(value...)}
|
||||
}
|
||||
|
||||
// Equal returns if a is equal to b.
|
||||
func (a Attr) Equal(b Attr) bool {
|
||||
return a.Key == b.Key && a.Value.Equal(b.Value)
|
||||
}
|
8
vendor/go.opentelemetry.io/otel/trace/internal/telemetry/doc.go
generated
vendored
Normal file
8
vendor/go.opentelemetry.io/otel/trace/internal/telemetry/doc.go
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
/*
|
||||
Package telemetry provides a lightweight representations of OpenTelemetry
|
||||
telemetry that is compatible with the OTLP JSON protobuf encoding.
|
||||
*/
|
||||
package telemetry // import "go.opentelemetry.io/otel/trace/internal/telemetry"
|
103
vendor/go.opentelemetry.io/otel/trace/internal/telemetry/id.go
generated
vendored
Normal file
103
vendor/go.opentelemetry.io/otel/trace/internal/telemetry/id.go
generated
vendored
Normal file
@ -0,0 +1,103 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package telemetry // import "go.opentelemetry.io/otel/trace/internal/telemetry"
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
const (
|
||||
traceIDSize = 16
|
||||
spanIDSize = 8
|
||||
)
|
||||
|
||||
// TraceID is a custom data type that is used for all trace IDs.
|
||||
type TraceID [traceIDSize]byte
|
||||
|
||||
// String returns the hex string representation form of a TraceID.
|
||||
func (tid TraceID) String() string {
|
||||
return hex.EncodeToString(tid[:])
|
||||
}
|
||||
|
||||
// IsEmpty returns false if id contains at least one non-zero byte.
|
||||
func (tid TraceID) IsEmpty() bool {
|
||||
return tid == [traceIDSize]byte{}
|
||||
}
|
||||
|
||||
// MarshalJSON converts the trace ID into a hex string enclosed in quotes.
|
||||
func (tid TraceID) MarshalJSON() ([]byte, error) {
|
||||
if tid.IsEmpty() {
|
||||
return []byte(`""`), nil
|
||||
}
|
||||
return marshalJSON(tid[:])
|
||||
}
|
||||
|
||||
// UnmarshalJSON inflates the trace ID from hex string, possibly enclosed in
|
||||
// quotes.
|
||||
func (tid *TraceID) UnmarshalJSON(data []byte) error {
|
||||
*tid = [traceIDSize]byte{}
|
||||
return unmarshalJSON(tid[:], data)
|
||||
}
|
||||
|
||||
// SpanID is a custom data type that is used for all span IDs.
|
||||
type SpanID [spanIDSize]byte
|
||||
|
||||
// String returns the hex string representation form of a SpanID.
|
||||
func (sid SpanID) String() string {
|
||||
return hex.EncodeToString(sid[:])
|
||||
}
|
||||
|
||||
// IsEmpty returns true if the span ID contains at least one non-zero byte.
|
||||
func (sid SpanID) IsEmpty() bool {
|
||||
return sid == [spanIDSize]byte{}
|
||||
}
|
||||
|
||||
// MarshalJSON converts span ID into a hex string enclosed in quotes.
|
||||
func (sid SpanID) MarshalJSON() ([]byte, error) {
|
||||
if sid.IsEmpty() {
|
||||
return []byte(`""`), nil
|
||||
}
|
||||
return marshalJSON(sid[:])
|
||||
}
|
||||
|
||||
// UnmarshalJSON decodes span ID from hex string, possibly enclosed in quotes.
|
||||
func (sid *SpanID) UnmarshalJSON(data []byte) error {
|
||||
*sid = [spanIDSize]byte{}
|
||||
return unmarshalJSON(sid[:], data)
|
||||
}
|
||||
|
||||
// marshalJSON converts id into a hex string enclosed in quotes.
|
||||
func marshalJSON(id []byte) ([]byte, error) {
|
||||
// Plus 2 quote chars at the start and end.
|
||||
hexLen := hex.EncodedLen(len(id)) + 2
|
||||
|
||||
b := make([]byte, hexLen)
|
||||
hex.Encode(b[1:hexLen-1], id)
|
||||
b[0], b[hexLen-1] = '"', '"'
|
||||
|
||||
return b, nil
|
||||
}
|
||||
|
||||
// unmarshalJSON inflates trace id from hex string, possibly enclosed in quotes.
|
||||
func unmarshalJSON(dst []byte, src []byte) error {
|
||||
if l := len(src); l >= 2 && src[0] == '"' && src[l-1] == '"' {
|
||||
src = src[1 : l-1]
|
||||
}
|
||||
nLen := len(src)
|
||||
if nLen == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
if len(dst) != hex.DecodedLen(nLen) {
|
||||
return errors.New("invalid length for ID")
|
||||
}
|
||||
|
||||
_, err := hex.Decode(dst, src)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot unmarshal ID from string '%s': %w", string(src), err)
|
||||
}
|
||||
return nil
|
||||
}
|
67
vendor/go.opentelemetry.io/otel/trace/internal/telemetry/number.go
generated
vendored
Normal file
67
vendor/go.opentelemetry.io/otel/trace/internal/telemetry/number.go
generated
vendored
Normal file
@ -0,0 +1,67 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package telemetry // import "go.opentelemetry.io/otel/trace/internal/telemetry"
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// protoInt64 represents the protobuf encoding of integers which can be either
|
||||
// strings or integers.
|
||||
type protoInt64 int64
|
||||
|
||||
// Int64 returns the protoInt64 as an int64.
|
||||
func (i *protoInt64) Int64() int64 { return int64(*i) }
|
||||
|
||||
// UnmarshalJSON decodes both strings and integers.
|
||||
func (i *protoInt64) UnmarshalJSON(data []byte) error {
|
||||
if data[0] == '"' {
|
||||
var str string
|
||||
if err := json.Unmarshal(data, &str); err != nil {
|
||||
return err
|
||||
}
|
||||
parsedInt, err := strconv.ParseInt(str, 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*i = protoInt64(parsedInt)
|
||||
} else {
|
||||
var parsedInt int64
|
||||
if err := json.Unmarshal(data, &parsedInt); err != nil {
|
||||
return err
|
||||
}
|
||||
*i = protoInt64(parsedInt)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// protoUint64 represents the protobuf encoding of integers which can be either
|
||||
// strings or integers.
|
||||
type protoUint64 uint64
|
||||
|
||||
// Int64 returns the protoUint64 as a uint64.
|
||||
func (i *protoUint64) Uint64() uint64 { return uint64(*i) }
|
||||
|
||||
// UnmarshalJSON decodes both strings and integers.
|
||||
func (i *protoUint64) UnmarshalJSON(data []byte) error {
|
||||
if data[0] == '"' {
|
||||
var str string
|
||||
if err := json.Unmarshal(data, &str); err != nil {
|
||||
return err
|
||||
}
|
||||
parsedUint, err := strconv.ParseUint(str, 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*i = protoUint64(parsedUint)
|
||||
} else {
|
||||
var parsedUint uint64
|
||||
if err := json.Unmarshal(data, &parsedUint); err != nil {
|
||||
return err
|
||||
}
|
||||
*i = protoUint64(parsedUint)
|
||||
}
|
||||
return nil
|
||||
}
|
66
vendor/go.opentelemetry.io/otel/trace/internal/telemetry/resource.go
generated
vendored
Normal file
66
vendor/go.opentelemetry.io/otel/trace/internal/telemetry/resource.go
generated
vendored
Normal file
@ -0,0 +1,66 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package telemetry // import "go.opentelemetry.io/otel/trace/internal/telemetry"
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
// Resource information.
|
||||
type Resource struct {
|
||||
// Attrs are the set of attributes that describe the resource. Attribute
|
||||
// keys MUST be unique (it is not allowed to have more than one attribute
|
||||
// with the same key).
|
||||
Attrs []Attr `json:"attributes,omitempty"`
|
||||
// DroppedAttrs is the number of dropped attributes. If the value
|
||||
// is 0, then no attributes were dropped.
|
||||
DroppedAttrs uint32 `json:"droppedAttributesCount,omitempty"`
|
||||
}
|
||||
|
||||
// UnmarshalJSON decodes the OTLP formatted JSON contained in data into r.
|
||||
func (r *Resource) UnmarshalJSON(data []byte) error {
|
||||
decoder := json.NewDecoder(bytes.NewReader(data))
|
||||
|
||||
t, err := decoder.Token()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if t != json.Delim('{') {
|
||||
return errors.New("invalid Resource type")
|
||||
}
|
||||
|
||||
for decoder.More() {
|
||||
keyIface, err := decoder.Token()
|
||||
if err != nil {
|
||||
if errors.Is(err, io.EOF) {
|
||||
// Empty.
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
key, ok := keyIface.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("invalid Resource field: %#v", keyIface)
|
||||
}
|
||||
|
||||
switch key {
|
||||
case "attributes":
|
||||
err = decoder.Decode(&r.Attrs)
|
||||
case "droppedAttributesCount", "dropped_attributes_count":
|
||||
err = decoder.Decode(&r.DroppedAttrs)
|
||||
default:
|
||||
// Skip unknown.
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
67
vendor/go.opentelemetry.io/otel/trace/internal/telemetry/scope.go
generated
vendored
Normal file
67
vendor/go.opentelemetry.io/otel/trace/internal/telemetry/scope.go
generated
vendored
Normal file
@ -0,0 +1,67 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package telemetry // import "go.opentelemetry.io/otel/trace/internal/telemetry"
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
// Scope is the identifying values of the instrumentation scope.
|
||||
type Scope struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
Version string `json:"version,omitempty"`
|
||||
Attrs []Attr `json:"attributes,omitempty"`
|
||||
DroppedAttrs uint32 `json:"droppedAttributesCount,omitempty"`
|
||||
}
|
||||
|
||||
// UnmarshalJSON decodes the OTLP formatted JSON contained in data into r.
|
||||
func (s *Scope) UnmarshalJSON(data []byte) error {
|
||||
decoder := json.NewDecoder(bytes.NewReader(data))
|
||||
|
||||
t, err := decoder.Token()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if t != json.Delim('{') {
|
||||
return errors.New("invalid Scope type")
|
||||
}
|
||||
|
||||
for decoder.More() {
|
||||
keyIface, err := decoder.Token()
|
||||
if err != nil {
|
||||
if errors.Is(err, io.EOF) {
|
||||
// Empty.
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
key, ok := keyIface.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("invalid Scope field: %#v", keyIface)
|
||||
}
|
||||
|
||||
switch key {
|
||||
case "name":
|
||||
err = decoder.Decode(&s.Name)
|
||||
case "version":
|
||||
err = decoder.Decode(&s.Version)
|
||||
case "attributes":
|
||||
err = decoder.Decode(&s.Attrs)
|
||||
case "droppedAttributesCount", "dropped_attributes_count":
|
||||
err = decoder.Decode(&s.DroppedAttrs)
|
||||
default:
|
||||
// Skip unknown.
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
460
vendor/go.opentelemetry.io/otel/trace/internal/telemetry/span.go
generated
vendored
Normal file
460
vendor/go.opentelemetry.io/otel/trace/internal/telemetry/span.go
generated
vendored
Normal file
@ -0,0 +1,460 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package telemetry // import "go.opentelemetry.io/otel/trace/internal/telemetry"
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
"time"
|
||||
)
|
||||
|
||||
// A Span represents a single operation performed by a single component of the
|
||||
// system.
|
||||
type Span struct {
|
||||
// A unique identifier for a trace. All spans from the same trace share
|
||||
// the same `trace_id`. The ID is a 16-byte array. An ID with all zeroes OR
|
||||
// of length other than 16 bytes is considered invalid (empty string in OTLP/JSON
|
||||
// is zero-length and thus is also invalid).
|
||||
//
|
||||
// This field is required.
|
||||
TraceID TraceID `json:"traceId,omitempty"`
|
||||
// A unique identifier for a span within a trace, assigned when the span
|
||||
// is created. The ID is an 8-byte array. An ID with all zeroes OR of length
|
||||
// other than 8 bytes is considered invalid (empty string in OTLP/JSON
|
||||
// is zero-length and thus is also invalid).
|
||||
//
|
||||
// This field is required.
|
||||
SpanID SpanID `json:"spanId,omitempty"`
|
||||
// trace_state conveys information about request position in multiple distributed tracing graphs.
|
||||
// It is a trace_state in w3c-trace-context format: https://www.w3.org/TR/trace-context/#tracestate-header
|
||||
// See also https://github.com/w3c/distributed-tracing for more details about this field.
|
||||
TraceState string `json:"traceState,omitempty"`
|
||||
// The `span_id` of this span's parent span. If this is a root span, then this
|
||||
// field must be empty. The ID is an 8-byte array.
|
||||
ParentSpanID SpanID `json:"parentSpanId,omitempty"`
|
||||
// Flags, a bit field.
|
||||
//
|
||||
// Bits 0-7 (8 least significant bits) are the trace flags as defined in W3C Trace
|
||||
// Context specification. To read the 8-bit W3C trace flag, use
|
||||
// `flags & SPAN_FLAGS_TRACE_FLAGS_MASK`.
|
||||
//
|
||||
// See https://www.w3.org/TR/trace-context-2/#trace-flags for the flag definitions.
|
||||
//
|
||||
// Bits 8 and 9 represent the 3 states of whether a span's parent
|
||||
// is remote. The states are (unknown, is not remote, is remote).
|
||||
// To read whether the value is known, use `(flags & SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK) != 0`.
|
||||
// To read whether the span is remote, use `(flags & SPAN_FLAGS_CONTEXT_IS_REMOTE_MASK) != 0`.
|
||||
//
|
||||
// When creating span messages, if the message is logically forwarded from another source
|
||||
// with an equivalent flags fields (i.e., usually another OTLP span message), the field SHOULD
|
||||
// be copied as-is. If creating from a source that does not have an equivalent flags field
|
||||
// (such as a runtime representation of an OpenTelemetry span), the high 22 bits MUST
|
||||
// be set to zero.
|
||||
// Readers MUST NOT assume that bits 10-31 (22 most significant bits) will be zero.
|
||||
//
|
||||
// [Optional].
|
||||
Flags uint32 `json:"flags,omitempty"`
|
||||
// A description of the span's operation.
|
||||
//
|
||||
// For example, the name can be a qualified method name or a file name
|
||||
// and a line number where the operation is called. A best practice is to use
|
||||
// the same display name at the same call point in an application.
|
||||
// This makes it easier to correlate spans in different traces.
|
||||
//
|
||||
// This field is semantically required to be set to non-empty string.
|
||||
// Empty value is equivalent to an unknown span name.
|
||||
//
|
||||
// This field is required.
|
||||
Name string `json:"name"`
|
||||
// Distinguishes between spans generated in a particular context. For example,
|
||||
// two spans with the same name may be distinguished using `CLIENT` (caller)
|
||||
// and `SERVER` (callee) to identify queueing latency associated with the span.
|
||||
Kind SpanKind `json:"kind,omitempty"`
|
||||
// start_time_unix_nano is the start time of the span. On the client side, this is the time
|
||||
// kept by the local machine where the span execution starts. On the server side, this
|
||||
// is the time when the server's application handler starts running.
|
||||
// Value is UNIX Epoch time in nanoseconds since 00:00:00 UTC on 1 January 1970.
|
||||
//
|
||||
// This field is semantically required and it is expected that end_time >= start_time.
|
||||
StartTime time.Time `json:"startTimeUnixNano,omitempty"`
|
||||
// end_time_unix_nano is the end time of the span. On the client side, this is the time
|
||||
// kept by the local machine where the span execution ends. On the server side, this
|
||||
// is the time when the server application handler stops running.
|
||||
// Value is UNIX Epoch time in nanoseconds since 00:00:00 UTC on 1 January 1970.
|
||||
//
|
||||
// This field is semantically required and it is expected that end_time >= start_time.
|
||||
EndTime time.Time `json:"endTimeUnixNano,omitempty"`
|
||||
// attributes is a collection of key/value pairs. Note, global attributes
|
||||
// like server name can be set using the resource API. Examples of attributes:
|
||||
//
|
||||
// "/http/user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36"
|
||||
// "/http/server_latency": 300
|
||||
// "example.com/myattribute": true
|
||||
// "example.com/score": 10.239
|
||||
//
|
||||
// The OpenTelemetry API specification further restricts the allowed value types:
|
||||
// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/common/README.md#attribute
|
||||
// Attribute keys MUST be unique (it is not allowed to have more than one
|
||||
// attribute with the same key).
|
||||
Attrs []Attr `json:"attributes,omitempty"`
|
||||
// dropped_attributes_count is the number of attributes that were discarded. Attributes
|
||||
// can be discarded because their keys are too long or because there are too many
|
||||
// attributes. If this value is 0, then no attributes were dropped.
|
||||
DroppedAttrs uint32 `json:"droppedAttributesCount,omitempty"`
|
||||
// events is a collection of Event items.
|
||||
Events []*SpanEvent `json:"events,omitempty"`
|
||||
// dropped_events_count is the number of dropped events. If the value is 0, then no
|
||||
// events were dropped.
|
||||
DroppedEvents uint32 `json:"droppedEventsCount,omitempty"`
|
||||
// links is a collection of Links, which are references from this span to a span
|
||||
// in the same or different trace.
|
||||
Links []*SpanLink `json:"links,omitempty"`
|
||||
// dropped_links_count is the number of dropped links after the maximum size was
|
||||
// enforced. If this value is 0, then no links were dropped.
|
||||
DroppedLinks uint32 `json:"droppedLinksCount,omitempty"`
|
||||
// An optional final status for this span. Semantically when Status isn't set, it means
|
||||
// span's status code is unset, i.e. assume STATUS_CODE_UNSET (code = 0).
|
||||
Status *Status `json:"status,omitempty"`
|
||||
}
|
||||
|
||||
// MarshalJSON encodes s into OTLP formatted JSON.
|
||||
func (s Span) MarshalJSON() ([]byte, error) {
|
||||
startT := s.StartTime.UnixNano()
|
||||
if s.StartTime.IsZero() || startT < 0 {
|
||||
startT = 0
|
||||
}
|
||||
|
||||
endT := s.EndTime.UnixNano()
|
||||
if s.EndTime.IsZero() || endT < 0 {
|
||||
endT = 0
|
||||
}
|
||||
|
||||
// Override non-empty default SpanID marshal and omitempty.
|
||||
var parentSpanId string
|
||||
if !s.ParentSpanID.IsEmpty() {
|
||||
b := make([]byte, hex.EncodedLen(spanIDSize))
|
||||
hex.Encode(b, s.ParentSpanID[:])
|
||||
parentSpanId = string(b)
|
||||
}
|
||||
|
||||
type Alias Span
|
||||
return json.Marshal(struct {
|
||||
Alias
|
||||
ParentSpanID string `json:"parentSpanId,omitempty"`
|
||||
StartTime uint64 `json:"startTimeUnixNano,omitempty"`
|
||||
EndTime uint64 `json:"endTimeUnixNano,omitempty"`
|
||||
}{
|
||||
Alias: Alias(s),
|
||||
ParentSpanID: parentSpanId,
|
||||
StartTime: uint64(startT), // nolint:gosec // >0 checked above.
|
||||
EndTime: uint64(endT), // nolint:gosec // >0 checked above.
|
||||
})
|
||||
}
|
||||
|
||||
// UnmarshalJSON decodes the OTLP formatted JSON contained in data into s.
|
||||
func (s *Span) UnmarshalJSON(data []byte) error {
|
||||
decoder := json.NewDecoder(bytes.NewReader(data))
|
||||
|
||||
t, err := decoder.Token()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if t != json.Delim('{') {
|
||||
return errors.New("invalid Span type")
|
||||
}
|
||||
|
||||
for decoder.More() {
|
||||
keyIface, err := decoder.Token()
|
||||
if err != nil {
|
||||
if errors.Is(err, io.EOF) {
|
||||
// Empty.
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
key, ok := keyIface.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("invalid Span field: %#v", keyIface)
|
||||
}
|
||||
|
||||
switch key {
|
||||
case "traceId", "trace_id":
|
||||
err = decoder.Decode(&s.TraceID)
|
||||
case "spanId", "span_id":
|
||||
err = decoder.Decode(&s.SpanID)
|
||||
case "traceState", "trace_state":
|
||||
err = decoder.Decode(&s.TraceState)
|
||||
case "parentSpanId", "parent_span_id":
|
||||
err = decoder.Decode(&s.ParentSpanID)
|
||||
case "flags":
|
||||
err = decoder.Decode(&s.Flags)
|
||||
case "name":
|
||||
err = decoder.Decode(&s.Name)
|
||||
case "kind":
|
||||
err = decoder.Decode(&s.Kind)
|
||||
case "startTimeUnixNano", "start_time_unix_nano":
|
||||
var val protoUint64
|
||||
err = decoder.Decode(&val)
|
||||
v := int64(min(val.Uint64(), math.MaxInt64)) // nolint: gosec // Overflow checked.
|
||||
s.StartTime = time.Unix(0, v)
|
||||
case "endTimeUnixNano", "end_time_unix_nano":
|
||||
var val protoUint64
|
||||
err = decoder.Decode(&val)
|
||||
v := int64(min(val.Uint64(), math.MaxInt64)) // nolint: gosec // Overflow checked.
|
||||
s.EndTime = time.Unix(0, v)
|
||||
case "attributes":
|
||||
err = decoder.Decode(&s.Attrs)
|
||||
case "droppedAttributesCount", "dropped_attributes_count":
|
||||
err = decoder.Decode(&s.DroppedAttrs)
|
||||
case "events":
|
||||
err = decoder.Decode(&s.Events)
|
||||
case "droppedEventsCount", "dropped_events_count":
|
||||
err = decoder.Decode(&s.DroppedEvents)
|
||||
case "links":
|
||||
err = decoder.Decode(&s.Links)
|
||||
case "droppedLinksCount", "dropped_links_count":
|
||||
err = decoder.Decode(&s.DroppedLinks)
|
||||
case "status":
|
||||
err = decoder.Decode(&s.Status)
|
||||
default:
|
||||
// Skip unknown.
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// SpanFlags represents constants used to interpret the
|
||||
// Span.flags field, which is protobuf 'fixed32' type and is to
|
||||
// be used as bit-fields. Each non-zero value defined in this enum is
|
||||
// a bit-mask. To extract the bit-field, for example, use an
|
||||
// expression like:
|
||||
//
|
||||
// (span.flags & SPAN_FLAGS_TRACE_FLAGS_MASK)
|
||||
//
|
||||
// See https://www.w3.org/TR/trace-context-2/#trace-flags for the flag definitions.
|
||||
//
|
||||
// Note that Span flags were introduced in version 1.1 of the
|
||||
// OpenTelemetry protocol. Older Span producers do not set this
|
||||
// field, consequently consumers should not rely on the absence of a
|
||||
// particular flag bit to indicate the presence of a particular feature.
|
||||
type SpanFlags int32
|
||||
|
||||
const (
|
||||
// Bits 0-7 are used for trace flags.
|
||||
SpanFlagsTraceFlagsMask SpanFlags = 255
|
||||
// Bits 8 and 9 are used to indicate that the parent span or link span is remote.
|
||||
// Bit 8 (`HAS_IS_REMOTE`) indicates whether the value is known.
|
||||
// Bit 9 (`IS_REMOTE`) indicates whether the span or link is remote.
|
||||
SpanFlagsContextHasIsRemoteMask SpanFlags = 256
|
||||
// SpanFlagsContextHasIsRemoteMask indicates the Span is remote.
|
||||
SpanFlagsContextIsRemoteMask SpanFlags = 512
|
||||
)
|
||||
|
||||
// SpanKind is the type of span. Can be used to specify additional relationships between spans
|
||||
// in addition to a parent/child relationship.
|
||||
type SpanKind int32
|
||||
|
||||
const (
|
||||
// Indicates that the span represents an internal operation within an application,
|
||||
// as opposed to an operation happening at the boundaries. Default value.
|
||||
SpanKindInternal SpanKind = 1
|
||||
// Indicates that the span covers server-side handling of an RPC or other
|
||||
// remote network request.
|
||||
SpanKindServer SpanKind = 2
|
||||
// Indicates that the span describes a request to some remote service.
|
||||
SpanKindClient SpanKind = 3
|
||||
// Indicates that the span describes a producer sending a message to a broker.
|
||||
// Unlike CLIENT and SERVER, there is often no direct critical path latency relationship
|
||||
// between producer and consumer spans. A PRODUCER span ends when the message was accepted
|
||||
// by the broker while the logical processing of the message might span a much longer time.
|
||||
SpanKindProducer SpanKind = 4
|
||||
// Indicates that the span describes consumer receiving a message from a broker.
|
||||
// Like the PRODUCER kind, there is often no direct critical path latency relationship
|
||||
// between producer and consumer spans.
|
||||
SpanKindConsumer SpanKind = 5
|
||||
)
|
||||
|
||||
// Event is a time-stamped annotation of the span, consisting of user-supplied
|
||||
// text description and key-value pairs.
|
||||
type SpanEvent struct {
|
||||
// time_unix_nano is the time the event occurred.
|
||||
Time time.Time `json:"timeUnixNano,omitempty"`
|
||||
// name of the event.
|
||||
// This field is semantically required to be set to non-empty string.
|
||||
Name string `json:"name,omitempty"`
|
||||
// attributes is a collection of attribute key/value pairs on the event.
|
||||
// Attribute keys MUST be unique (it is not allowed to have more than one
|
||||
// attribute with the same key).
|
||||
Attrs []Attr `json:"attributes,omitempty"`
|
||||
// dropped_attributes_count is the number of dropped attributes. If the value is 0,
|
||||
// then no attributes were dropped.
|
||||
DroppedAttrs uint32 `json:"droppedAttributesCount,omitempty"`
|
||||
}
|
||||
|
||||
// MarshalJSON encodes e into OTLP formatted JSON.
|
||||
func (e SpanEvent) MarshalJSON() ([]byte, error) {
|
||||
t := e.Time.UnixNano()
|
||||
if e.Time.IsZero() || t < 0 {
|
||||
t = 0
|
||||
}
|
||||
|
||||
type Alias SpanEvent
|
||||
return json.Marshal(struct {
|
||||
Alias
|
||||
Time uint64 `json:"timeUnixNano,omitempty"`
|
||||
}{
|
||||
Alias: Alias(e),
|
||||
Time: uint64(t), // nolint: gosec // >0 checked above
|
||||
})
|
||||
}
|
||||
|
||||
// UnmarshalJSON decodes the OTLP formatted JSON contained in data into se.
|
||||
func (se *SpanEvent) UnmarshalJSON(data []byte) error {
|
||||
decoder := json.NewDecoder(bytes.NewReader(data))
|
||||
|
||||
t, err := decoder.Token()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if t != json.Delim('{') {
|
||||
return errors.New("invalid SpanEvent type")
|
||||
}
|
||||
|
||||
for decoder.More() {
|
||||
keyIface, err := decoder.Token()
|
||||
if err != nil {
|
||||
if errors.Is(err, io.EOF) {
|
||||
// Empty.
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
key, ok := keyIface.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("invalid SpanEvent field: %#v", keyIface)
|
||||
}
|
||||
|
||||
switch key {
|
||||
case "timeUnixNano", "time_unix_nano":
|
||||
var val protoUint64
|
||||
err = decoder.Decode(&val)
|
||||
v := int64(min(val.Uint64(), math.MaxInt64)) // nolint: gosec // Overflow checked.
|
||||
se.Time = time.Unix(0, v)
|
||||
case "name":
|
||||
err = decoder.Decode(&se.Name)
|
||||
case "attributes":
|
||||
err = decoder.Decode(&se.Attrs)
|
||||
case "droppedAttributesCount", "dropped_attributes_count":
|
||||
err = decoder.Decode(&se.DroppedAttrs)
|
||||
default:
|
||||
// Skip unknown.
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// A pointer from the current span to another span in the same trace or in a
|
||||
// different trace. For example, this can be used in batching operations,
|
||||
// where a single batch handler processes multiple requests from different
|
||||
// traces or when the handler receives a request from a different project.
|
||||
type SpanLink struct {
|
||||
// A unique identifier of a trace that this linked span is part of. The ID is a
|
||||
// 16-byte array.
|
||||
TraceID TraceID `json:"traceId,omitempty"`
|
||||
// A unique identifier for the linked span. The ID is an 8-byte array.
|
||||
SpanID SpanID `json:"spanId,omitempty"`
|
||||
// The trace_state associated with the link.
|
||||
TraceState string `json:"traceState,omitempty"`
|
||||
// attributes is a collection of attribute key/value pairs on the link.
|
||||
// Attribute keys MUST be unique (it is not allowed to have more than one
|
||||
// attribute with the same key).
|
||||
Attrs []Attr `json:"attributes,omitempty"`
|
||||
// dropped_attributes_count is the number of dropped attributes. If the value is 0,
|
||||
// then no attributes were dropped.
|
||||
DroppedAttrs uint32 `json:"droppedAttributesCount,omitempty"`
|
||||
// Flags, a bit field.
|
||||
//
|
||||
// Bits 0-7 (8 least significant bits) are the trace flags as defined in W3C Trace
|
||||
// Context specification. To read the 8-bit W3C trace flag, use
|
||||
// `flags & SPAN_FLAGS_TRACE_FLAGS_MASK`.
|
||||
//
|
||||
// See https://www.w3.org/TR/trace-context-2/#trace-flags for the flag definitions.
|
||||
//
|
||||
// Bits 8 and 9 represent the 3 states of whether the link is remote.
|
||||
// The states are (unknown, is not remote, is remote).
|
||||
// To read whether the value is known, use `(flags & SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK) != 0`.
|
||||
// To read whether the link is remote, use `(flags & SPAN_FLAGS_CONTEXT_IS_REMOTE_MASK) != 0`.
|
||||
//
|
||||
// Readers MUST NOT assume that bits 10-31 (22 most significant bits) will be zero.
|
||||
// When creating new spans, bits 10-31 (most-significant 22-bits) MUST be zero.
|
||||
//
|
||||
// [Optional].
|
||||
Flags uint32 `json:"flags,omitempty"`
|
||||
}
|
||||
|
||||
// UnmarshalJSON decodes the OTLP formatted JSON contained in data into sl.
|
||||
func (sl *SpanLink) UnmarshalJSON(data []byte) error {
|
||||
decoder := json.NewDecoder(bytes.NewReader(data))
|
||||
|
||||
t, err := decoder.Token()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if t != json.Delim('{') {
|
||||
return errors.New("invalid SpanLink type")
|
||||
}
|
||||
|
||||
for decoder.More() {
|
||||
keyIface, err := decoder.Token()
|
||||
if err != nil {
|
||||
if errors.Is(err, io.EOF) {
|
||||
// Empty.
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
key, ok := keyIface.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("invalid SpanLink field: %#v", keyIface)
|
||||
}
|
||||
|
||||
switch key {
|
||||
case "traceId", "trace_id":
|
||||
err = decoder.Decode(&sl.TraceID)
|
||||
case "spanId", "span_id":
|
||||
err = decoder.Decode(&sl.SpanID)
|
||||
case "traceState", "trace_state":
|
||||
err = decoder.Decode(&sl.TraceState)
|
||||
case "attributes":
|
||||
err = decoder.Decode(&sl.Attrs)
|
||||
case "droppedAttributesCount", "dropped_attributes_count":
|
||||
err = decoder.Decode(&sl.DroppedAttrs)
|
||||
case "flags":
|
||||
err = decoder.Decode(&sl.Flags)
|
||||
default:
|
||||
// Skip unknown.
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
40
vendor/go.opentelemetry.io/otel/trace/internal/telemetry/status.go
generated
vendored
Normal file
40
vendor/go.opentelemetry.io/otel/trace/internal/telemetry/status.go
generated
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package telemetry // import "go.opentelemetry.io/otel/trace/internal/telemetry"
|
||||
|
||||
// For the semantics of status codes see
|
||||
// https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/api.md#set-status
|
||||
type StatusCode int32
|
||||
|
||||
const (
|
||||
// The default status.
|
||||
StatusCodeUnset StatusCode = 0
|
||||
// The Span has been validated by an Application developer or Operator to
|
||||
// have completed successfully.
|
||||
StatusCodeOK StatusCode = 1
|
||||
// The Span contains an error.
|
||||
StatusCodeError StatusCode = 2
|
||||
)
|
||||
|
||||
var statusCodeStrings = []string{
|
||||
"Unset",
|
||||
"OK",
|
||||
"Error",
|
||||
}
|
||||
|
||||
func (s StatusCode) String() string {
|
||||
if s >= 0 && int(s) < len(statusCodeStrings) {
|
||||
return statusCodeStrings[s]
|
||||
}
|
||||
return "<unknown telemetry.StatusCode>"
|
||||
}
|
||||
|
||||
// The Status type defines a logical error model that is suitable for different
|
||||
// programming environments, including REST APIs and RPC APIs.
|
||||
type Status struct {
|
||||
// A developer-facing human readable error message.
|
||||
Message string `json:"message,omitempty"`
|
||||
// The status code.
|
||||
Code StatusCode `json:"code,omitempty"`
|
||||
}
|
189
vendor/go.opentelemetry.io/otel/trace/internal/telemetry/traces.go
generated
vendored
Normal file
189
vendor/go.opentelemetry.io/otel/trace/internal/telemetry/traces.go
generated
vendored
Normal file
@ -0,0 +1,189 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package telemetry // import "go.opentelemetry.io/otel/trace/internal/telemetry"
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
// Traces represents the traces data that can be stored in a persistent storage,
|
||||
// OR can be embedded by other protocols that transfer OTLP traces data but do
|
||||
// not implement the OTLP protocol.
|
||||
//
|
||||
// The main difference between this message and collector protocol is that
|
||||
// in this message there will not be any "control" or "metadata" specific to
|
||||
// OTLP protocol.
|
||||
//
|
||||
// When new fields are added into this message, the OTLP request MUST be updated
|
||||
// as well.
|
||||
type Traces struct {
|
||||
// An array of ResourceSpans.
|
||||
// For data coming from a single resource this array will typically contain
|
||||
// one element. Intermediary nodes that receive data from multiple origins
|
||||
// typically batch the data before forwarding further and in that case this
|
||||
// array will contain multiple elements.
|
||||
ResourceSpans []*ResourceSpans `json:"resourceSpans,omitempty"`
|
||||
}
|
||||
|
||||
// UnmarshalJSON decodes the OTLP formatted JSON contained in data into td.
|
||||
func (td *Traces) UnmarshalJSON(data []byte) error {
|
||||
decoder := json.NewDecoder(bytes.NewReader(data))
|
||||
|
||||
t, err := decoder.Token()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if t != json.Delim('{') {
|
||||
return errors.New("invalid TracesData type")
|
||||
}
|
||||
|
||||
for decoder.More() {
|
||||
keyIface, err := decoder.Token()
|
||||
if err != nil {
|
||||
if errors.Is(err, io.EOF) {
|
||||
// Empty.
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
key, ok := keyIface.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("invalid TracesData field: %#v", keyIface)
|
||||
}
|
||||
|
||||
switch key {
|
||||
case "resourceSpans", "resource_spans":
|
||||
err = decoder.Decode(&td.ResourceSpans)
|
||||
default:
|
||||
// Skip unknown.
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// A collection of ScopeSpans from a Resource.
|
||||
type ResourceSpans struct {
|
||||
// The resource for the spans in this message.
|
||||
// If this field is not set then no resource info is known.
|
||||
Resource Resource `json:"resource"`
|
||||
// A list of ScopeSpans that originate from a resource.
|
||||
ScopeSpans []*ScopeSpans `json:"scopeSpans,omitempty"`
|
||||
// This schema_url applies to the data in the "resource" field. It does not apply
|
||||
// to the data in the "scope_spans" field which have their own schema_url field.
|
||||
SchemaURL string `json:"schemaUrl,omitempty"`
|
||||
}
|
||||
|
||||
// UnmarshalJSON decodes the OTLP formatted JSON contained in data into rs.
|
||||
func (rs *ResourceSpans) UnmarshalJSON(data []byte) error {
|
||||
decoder := json.NewDecoder(bytes.NewReader(data))
|
||||
|
||||
t, err := decoder.Token()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if t != json.Delim('{') {
|
||||
return errors.New("invalid ResourceSpans type")
|
||||
}
|
||||
|
||||
for decoder.More() {
|
||||
keyIface, err := decoder.Token()
|
||||
if err != nil {
|
||||
if errors.Is(err, io.EOF) {
|
||||
// Empty.
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
key, ok := keyIface.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("invalid ResourceSpans field: %#v", keyIface)
|
||||
}
|
||||
|
||||
switch key {
|
||||
case "resource":
|
||||
err = decoder.Decode(&rs.Resource)
|
||||
case "scopeSpans", "scope_spans":
|
||||
err = decoder.Decode(&rs.ScopeSpans)
|
||||
case "schemaUrl", "schema_url":
|
||||
err = decoder.Decode(&rs.SchemaURL)
|
||||
default:
|
||||
// Skip unknown.
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// A collection of Spans produced by an InstrumentationScope.
|
||||
type ScopeSpans struct {
|
||||
// The instrumentation scope information for the spans in this message.
|
||||
// Semantically when InstrumentationScope isn't set, it is equivalent with
|
||||
// an empty instrumentation scope name (unknown).
|
||||
Scope *Scope `json:"scope"`
|
||||
// A list of Spans that originate from an instrumentation scope.
|
||||
Spans []*Span `json:"spans,omitempty"`
|
||||
// The Schema URL, if known. This is the identifier of the Schema that the span data
|
||||
// is recorded in. To learn more about Schema URL see
|
||||
// https://opentelemetry.io/docs/specs/otel/schemas/#schema-url
|
||||
// This schema_url applies to all spans and span events in the "spans" field.
|
||||
SchemaURL string `json:"schemaUrl,omitempty"`
|
||||
}
|
||||
|
||||
// UnmarshalJSON decodes the OTLP formatted JSON contained in data into ss.
|
||||
func (ss *ScopeSpans) UnmarshalJSON(data []byte) error {
|
||||
decoder := json.NewDecoder(bytes.NewReader(data))
|
||||
|
||||
t, err := decoder.Token()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if t != json.Delim('{') {
|
||||
return errors.New("invalid ScopeSpans type")
|
||||
}
|
||||
|
||||
for decoder.More() {
|
||||
keyIface, err := decoder.Token()
|
||||
if err != nil {
|
||||
if errors.Is(err, io.EOF) {
|
||||
// Empty.
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
key, ok := keyIface.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("invalid ScopeSpans field: %#v", keyIface)
|
||||
}
|
||||
|
||||
switch key {
|
||||
case "scope":
|
||||
err = decoder.Decode(&ss.Scope)
|
||||
case "spans":
|
||||
err = decoder.Decode(&ss.Spans)
|
||||
case "schemaUrl", "schema_url":
|
||||
err = decoder.Decode(&ss.SchemaURL)
|
||||
default:
|
||||
// Skip unknown.
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
453
vendor/go.opentelemetry.io/otel/trace/internal/telemetry/value.go
generated
vendored
Normal file
453
vendor/go.opentelemetry.io/otel/trace/internal/telemetry/value.go
generated
vendored
Normal file
@ -0,0 +1,453 @@
|
||||
// Copyright The OpenTelemetry Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package telemetry // import "go.opentelemetry.io/otel/trace/internal/telemetry"
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"cmp"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
"slices"
|
||||
"strconv"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// A Value represents a structured value.
|
||||
// A zero value is valid and represents an empty value.
|
||||
type Value struct {
|
||||
// Ensure forward compatibility by explicitly making this not comparable.
|
||||
noCmp [0]func() //nolint: unused // This is indeed used.
|
||||
|
||||
// num holds the value for Int64, Float64, and Bool. It holds the length
|
||||
// for String, Bytes, Slice, Map.
|
||||
num uint64
|
||||
// any holds either the KindBool, KindInt64, KindFloat64, stringptr,
|
||||
// bytesptr, sliceptr, or mapptr. If KindBool, KindInt64, or KindFloat64
|
||||
// then the value of Value is in num as described above. Otherwise, it
|
||||
// contains the value wrapped in the appropriate type.
|
||||
any any
|
||||
}
|
||||
|
||||
type (
|
||||
// sliceptr represents a value in Value.any for KindString Values.
|
||||
stringptr *byte
|
||||
// bytesptr represents a value in Value.any for KindBytes Values.
|
||||
bytesptr *byte
|
||||
// sliceptr represents a value in Value.any for KindSlice Values.
|
||||
sliceptr *Value
|
||||
// mapptr represents a value in Value.any for KindMap Values.
|
||||
mapptr *Attr
|
||||
)
|
||||
|
||||
// ValueKind is the kind of a [Value].
|
||||
type ValueKind int
|
||||
|
||||
// ValueKind values.
|
||||
const (
|
||||
ValueKindEmpty ValueKind = iota
|
||||
ValueKindBool
|
||||
ValueKindFloat64
|
||||
ValueKindInt64
|
||||
ValueKindString
|
||||
ValueKindBytes
|
||||
ValueKindSlice
|
||||
ValueKindMap
|
||||
)
|
||||
|
||||
var valueKindStrings = []string{
|
||||
"Empty",
|
||||
"Bool",
|
||||
"Float64",
|
||||
"Int64",
|
||||
"String",
|
||||
"Bytes",
|
||||
"Slice",
|
||||
"Map",
|
||||
}
|
||||
|
||||
func (k ValueKind) String() string {
|
||||
if k >= 0 && int(k) < len(valueKindStrings) {
|
||||
return valueKindStrings[k]
|
||||
}
|
||||
return "<unknown telemetry.ValueKind>"
|
||||
}
|
||||
|
||||
// StringValue returns a new [Value] for a string.
|
||||
func StringValue(v string) Value {
|
||||
return Value{
|
||||
num: uint64(len(v)),
|
||||
any: stringptr(unsafe.StringData(v)),
|
||||
}
|
||||
}
|
||||
|
||||
// IntValue returns a [Value] for an int.
|
||||
func IntValue(v int) Value { return Int64Value(int64(v)) }
|
||||
|
||||
// Int64Value returns a [Value] for an int64.
|
||||
func Int64Value(v int64) Value {
|
||||
return Value{
|
||||
num: uint64(v), // nolint: gosec // Store raw bytes.
|
||||
any: ValueKindInt64,
|
||||
}
|
||||
}
|
||||
|
||||
// Float64Value returns a [Value] for a float64.
|
||||
func Float64Value(v float64) Value {
|
||||
return Value{num: math.Float64bits(v), any: ValueKindFloat64}
|
||||
}
|
||||
|
||||
// BoolValue returns a [Value] for a bool.
|
||||
func BoolValue(v bool) Value { //nolint:revive // Not a control flag.
|
||||
var n uint64
|
||||
if v {
|
||||
n = 1
|
||||
}
|
||||
return Value{num: n, any: ValueKindBool}
|
||||
}
|
||||
|
||||
// BytesValue returns a [Value] for a byte slice. The passed slice must not be
|
||||
// changed after it is passed.
|
||||
func BytesValue(v []byte) Value {
|
||||
return Value{
|
||||
num: uint64(len(v)),
|
||||
any: bytesptr(unsafe.SliceData(v)),
|
||||
}
|
||||
}
|
||||
|
||||
// SliceValue returns a [Value] for a slice of [Value]. The passed slice must
|
||||
// not be changed after it is passed.
|
||||
func SliceValue(vs ...Value) Value {
|
||||
return Value{
|
||||
num: uint64(len(vs)),
|
||||
any: sliceptr(unsafe.SliceData(vs)),
|
||||
}
|
||||
}
|
||||
|
||||
// MapValue returns a new [Value] for a slice of key-value pairs. The passed
|
||||
// slice must not be changed after it is passed.
|
||||
func MapValue(kvs ...Attr) Value {
|
||||
return Value{
|
||||
num: uint64(len(kvs)),
|
||||
any: mapptr(unsafe.SliceData(kvs)),
|
||||
}
|
||||
}
|
||||
|
||||
// AsString returns the value held by v as a string.
|
||||
func (v Value) AsString() string {
|
||||
if sp, ok := v.any.(stringptr); ok {
|
||||
return unsafe.String(sp, v.num)
|
||||
}
|
||||
// TODO: error handle
|
||||
return ""
|
||||
}
|
||||
|
||||
// asString returns the value held by v as a string. It will panic if the Value
|
||||
// is not KindString.
|
||||
func (v Value) asString() string {
|
||||
return unsafe.String(v.any.(stringptr), v.num)
|
||||
}
|
||||
|
||||
// AsInt64 returns the value held by v as an int64.
|
||||
func (v Value) AsInt64() int64 {
|
||||
if v.Kind() != ValueKindInt64 {
|
||||
// TODO: error handle
|
||||
return 0
|
||||
}
|
||||
return v.asInt64()
|
||||
}
|
||||
|
||||
// asInt64 returns the value held by v as an int64. If v is not of KindInt64,
|
||||
// this will return garbage.
|
||||
func (v Value) asInt64() int64 {
|
||||
// Assumes v.num was a valid int64 (overflow not checked).
|
||||
return int64(v.num) // nolint: gosec
|
||||
}
|
||||
|
||||
// AsBool returns the value held by v as a bool.
|
||||
func (v Value) AsBool() bool {
|
||||
if v.Kind() != ValueKindBool {
|
||||
// TODO: error handle
|
||||
return false
|
||||
}
|
||||
return v.asBool()
|
||||
}
|
||||
|
||||
// asBool returns the value held by v as a bool. If v is not of KindBool, this
|
||||
// will return garbage.
|
||||
func (v Value) asBool() bool { return v.num == 1 }
|
||||
|
||||
// AsFloat64 returns the value held by v as a float64.
|
||||
func (v Value) AsFloat64() float64 {
|
||||
if v.Kind() != ValueKindFloat64 {
|
||||
// TODO: error handle
|
||||
return 0
|
||||
}
|
||||
return v.asFloat64()
|
||||
}
|
||||
|
||||
// asFloat64 returns the value held by v as a float64. If v is not of
|
||||
// KindFloat64, this will return garbage.
|
||||
func (v Value) asFloat64() float64 { return math.Float64frombits(v.num) }
|
||||
|
||||
// AsBytes returns the value held by v as a []byte.
|
||||
func (v Value) AsBytes() []byte {
|
||||
if sp, ok := v.any.(bytesptr); ok {
|
||||
return unsafe.Slice((*byte)(sp), v.num)
|
||||
}
|
||||
// TODO: error handle
|
||||
return nil
|
||||
}
|
||||
|
||||
// asBytes returns the value held by v as a []byte. It will panic if the Value
|
||||
// is not KindBytes.
|
||||
func (v Value) asBytes() []byte {
|
||||
return unsafe.Slice((*byte)(v.any.(bytesptr)), v.num)
|
||||
}
|
||||
|
||||
// AsSlice returns the value held by v as a []Value.
|
||||
func (v Value) AsSlice() []Value {
|
||||
if sp, ok := v.any.(sliceptr); ok {
|
||||
return unsafe.Slice((*Value)(sp), v.num)
|
||||
}
|
||||
// TODO: error handle
|
||||
return nil
|
||||
}
|
||||
|
||||
// asSlice returns the value held by v as a []Value. It will panic if the Value
|
||||
// is not KindSlice.
|
||||
func (v Value) asSlice() []Value {
|
||||
return unsafe.Slice((*Value)(v.any.(sliceptr)), v.num)
|
||||
}
|
||||
|
||||
// AsMap returns the value held by v as a []Attr.
|
||||
func (v Value) AsMap() []Attr {
|
||||
if sp, ok := v.any.(mapptr); ok {
|
||||
return unsafe.Slice((*Attr)(sp), v.num)
|
||||
}
|
||||
// TODO: error handle
|
||||
return nil
|
||||
}
|
||||
|
||||
// asMap returns the value held by v as a []Attr. It will panic if the
|
||||
// Value is not KindMap.
|
||||
func (v Value) asMap() []Attr {
|
||||
return unsafe.Slice((*Attr)(v.any.(mapptr)), v.num)
|
||||
}
|
||||
|
||||
// Kind returns the Kind of v.
|
||||
func (v Value) Kind() ValueKind {
|
||||
switch x := v.any.(type) {
|
||||
case ValueKind:
|
||||
return x
|
||||
case stringptr:
|
||||
return ValueKindString
|
||||
case bytesptr:
|
||||
return ValueKindBytes
|
||||
case sliceptr:
|
||||
return ValueKindSlice
|
||||
case mapptr:
|
||||
return ValueKindMap
|
||||
default:
|
||||
return ValueKindEmpty
|
||||
}
|
||||
}
|
||||
|
||||
// Empty returns if v does not hold any value.
|
||||
func (v Value) Empty() bool { return v.Kind() == ValueKindEmpty }
|
||||
|
||||
// Equal returns if v is equal to w.
|
||||
func (v Value) Equal(w Value) bool {
|
||||
k1 := v.Kind()
|
||||
k2 := w.Kind()
|
||||
if k1 != k2 {
|
||||
return false
|
||||
}
|
||||
switch k1 {
|
||||
case ValueKindInt64, ValueKindBool:
|
||||
return v.num == w.num
|
||||
case ValueKindString:
|
||||
return v.asString() == w.asString()
|
||||
case ValueKindFloat64:
|
||||
return v.asFloat64() == w.asFloat64()
|
||||
case ValueKindSlice:
|
||||
return slices.EqualFunc(v.asSlice(), w.asSlice(), Value.Equal)
|
||||
case ValueKindMap:
|
||||
sv := sortMap(v.asMap())
|
||||
sw := sortMap(w.asMap())
|
||||
return slices.EqualFunc(sv, sw, Attr.Equal)
|
||||
case ValueKindBytes:
|
||||
return bytes.Equal(v.asBytes(), w.asBytes())
|
||||
case ValueKindEmpty:
|
||||
return true
|
||||
default:
|
||||
// TODO: error handle
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func sortMap(m []Attr) []Attr {
|
||||
sm := make([]Attr, len(m))
|
||||
copy(sm, m)
|
||||
slices.SortFunc(sm, func(a, b Attr) int {
|
||||
return cmp.Compare(a.Key, b.Key)
|
||||
})
|
||||
|
||||
return sm
|
||||
}
|
||||
|
||||
// String returns Value's value as a string, formatted like [fmt.Sprint].
|
||||
//
|
||||
// The returned string is meant for debugging;
|
||||
// the string representation is not stable.
|
||||
func (v Value) String() string {
|
||||
switch v.Kind() {
|
||||
case ValueKindString:
|
||||
return v.asString()
|
||||
case ValueKindInt64:
|
||||
// Assumes v.num was a valid int64 (overflow not checked).
|
||||
return strconv.FormatInt(int64(v.num), 10) // nolint: gosec
|
||||
case ValueKindFloat64:
|
||||
return strconv.FormatFloat(v.asFloat64(), 'g', -1, 64)
|
||||
case ValueKindBool:
|
||||
return strconv.FormatBool(v.asBool())
|
||||
case ValueKindBytes:
|
||||
return fmt.Sprint(v.asBytes())
|
||||
case ValueKindMap:
|
||||
return fmt.Sprint(v.asMap())
|
||||
case ValueKindSlice:
|
||||
return fmt.Sprint(v.asSlice())
|
||||
case ValueKindEmpty:
|
||||
return "<nil>"
|
||||
default:
|
||||
// Try to handle this as gracefully as possible.
|
||||
//
|
||||
// Don't panic here. The goal here is to have developers find this
|
||||
// first if a slog.Kind is is not handled. It is
|
||||
// preferable to have user's open issue asking why their attributes
|
||||
// have a "unhandled: " prefix than say that their code is panicking.
|
||||
return fmt.Sprintf("<unhandled telemetry.ValueKind: %s>", v.Kind())
|
||||
}
|
||||
}
|
||||
|
||||
// MarshalJSON encodes v into OTLP formatted JSON.
|
||||
func (v *Value) MarshalJSON() ([]byte, error) {
|
||||
switch v.Kind() {
|
||||
case ValueKindString:
|
||||
return json.Marshal(struct {
|
||||
Value string `json:"stringValue"`
|
||||
}{v.asString()})
|
||||
case ValueKindInt64:
|
||||
return json.Marshal(struct {
|
||||
Value string `json:"intValue"`
|
||||
}{strconv.FormatInt(int64(v.num), 10)}) // nolint: gosec // From raw bytes.
|
||||
case ValueKindFloat64:
|
||||
return json.Marshal(struct {
|
||||
Value float64 `json:"doubleValue"`
|
||||
}{v.asFloat64()})
|
||||
case ValueKindBool:
|
||||
return json.Marshal(struct {
|
||||
Value bool `json:"boolValue"`
|
||||
}{v.asBool()})
|
||||
case ValueKindBytes:
|
||||
return json.Marshal(struct {
|
||||
Value []byte `json:"bytesValue"`
|
||||
}{v.asBytes()})
|
||||
case ValueKindMap:
|
||||
return json.Marshal(struct {
|
||||
Value struct {
|
||||
Values []Attr `json:"values"`
|
||||
} `json:"kvlistValue"`
|
||||
}{struct {
|
||||
Values []Attr `json:"values"`
|
||||
}{v.asMap()}})
|
||||
case ValueKindSlice:
|
||||
return json.Marshal(struct {
|
||||
Value struct {
|
||||
Values []Value `json:"values"`
|
||||
} `json:"arrayValue"`
|
||||
}{struct {
|
||||
Values []Value `json:"values"`
|
||||
}{v.asSlice()}})
|
||||
case ValueKindEmpty:
|
||||
return nil, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown Value kind: %s", v.Kind().String())
|
||||
}
|
||||
}
|
||||
|
||||
// UnmarshalJSON decodes the OTLP formatted JSON contained in data into v.
|
||||
func (v *Value) UnmarshalJSON(data []byte) error {
|
||||
decoder := json.NewDecoder(bytes.NewReader(data))
|
||||
|
||||
t, err := decoder.Token()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if t != json.Delim('{') {
|
||||
return errors.New("invalid Value type")
|
||||
}
|
||||
|
||||
for decoder.More() {
|
||||
keyIface, err := decoder.Token()
|
||||
if err != nil {
|
||||
if errors.Is(err, io.EOF) {
|
||||
// Empty.
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
key, ok := keyIface.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("invalid Value key: %#v", keyIface)
|
||||
}
|
||||
|
||||
switch key {
|
||||
case "stringValue", "string_value":
|
||||
var val string
|
||||
err = decoder.Decode(&val)
|
||||
*v = StringValue(val)
|
||||
case "boolValue", "bool_value":
|
||||
var val bool
|
||||
err = decoder.Decode(&val)
|
||||
*v = BoolValue(val)
|
||||
case "intValue", "int_value":
|
||||
var val protoInt64
|
||||
err = decoder.Decode(&val)
|
||||
*v = Int64Value(val.Int64())
|
||||
case "doubleValue", "double_value":
|
||||
var val float64
|
||||
err = decoder.Decode(&val)
|
||||
*v = Float64Value(val)
|
||||
case "bytesValue", "bytes_value":
|
||||
var val64 string
|
||||
if err := decoder.Decode(&val64); err != nil {
|
||||
return err
|
||||
}
|
||||
var val []byte
|
||||
val, err = base64.StdEncoding.DecodeString(val64)
|
||||
*v = BytesValue(val)
|
||||
case "arrayValue", "array_value":
|
||||
var val struct{ Values []Value }
|
||||
err = decoder.Decode(&val)
|
||||
*v = SliceValue(val.Values...)
|
||||
case "kvlistValue", "kvlist_value":
|
||||
var val struct{ Values []Attr }
|
||||
err = decoder.Decode(&val)
|
||||
*v = MapValue(val.Values...)
|
||||
default:
|
||||
// Skip unknown.
|
||||
continue
|
||||
}
|
||||
// Use first valid. Ignore the rest.
|
||||
return err
|
||||
}
|
||||
|
||||
// Only unknown fields. Return nil without unmarshaling any value.
|
||||
return nil
|
||||
}
|
20
vendor/go.opentelemetry.io/otel/trace/noop.go
generated
vendored
20
vendor/go.opentelemetry.io/otel/trace/noop.go
generated
vendored
@ -82,4 +82,22 @@ func (noopSpan) AddLink(Link) {}
|
||||
func (noopSpan) SetName(string) {}
|
||||
|
||||
// TracerProvider returns a no-op TracerProvider.
|
||||
func (noopSpan) TracerProvider() TracerProvider { return noopTracerProvider{} }
|
||||
func (s noopSpan) TracerProvider() TracerProvider {
|
||||
return s.tracerProvider(autoInstEnabled)
|
||||
}
|
||||
|
||||
// autoInstEnabled defines if the auto-instrumentation SDK is enabled.
|
||||
//
|
||||
// The auto-instrumentation is expected to overwrite this value to true when it
|
||||
// attaches to the process.
|
||||
var autoInstEnabled = new(bool)
|
||||
|
||||
// tracerProvider return a noopTracerProvider if autoEnabled is false,
|
||||
// otherwise it will return a TracerProvider from the sdk package used in
|
||||
// auto-instrumentation.
|
||||
func (noopSpan) tracerProvider(autoEnabled *bool) TracerProvider {
|
||||
if *autoEnabled {
|
||||
return newAutoTracerProvider()
|
||||
}
|
||||
return noopTracerProvider{}
|
||||
}
|
||||
|
2
vendor/go.opentelemetry.io/otel/version.go
generated
vendored
2
vendor/go.opentelemetry.io/otel/version.go
generated
vendored
@ -5,5 +5,5 @@ package otel // import "go.opentelemetry.io/otel"
|
||||
|
||||
// Version is the current release version of OpenTelemetry in use.
|
||||
func Version() string {
|
||||
return "1.33.0"
|
||||
return "1.35.0"
|
||||
}
|
||||
|
7
vendor/go.opentelemetry.io/otel/versions.yaml
generated
vendored
7
vendor/go.opentelemetry.io/otel/versions.yaml
generated
vendored
@ -3,7 +3,7 @@
|
||||
|
||||
module-sets:
|
||||
stable-v1:
|
||||
version: v1.33.0
|
||||
version: v1.35.0
|
||||
modules:
|
||||
- go.opentelemetry.io/otel
|
||||
- go.opentelemetry.io/otel/bridge/opencensus
|
||||
@ -23,11 +23,11 @@ module-sets:
|
||||
- go.opentelemetry.io/otel/sdk/metric
|
||||
- go.opentelemetry.io/otel/trace
|
||||
experimental-metrics:
|
||||
version: v0.55.0
|
||||
version: v0.57.0
|
||||
modules:
|
||||
- go.opentelemetry.io/otel/exporters/prometheus
|
||||
experimental-logs:
|
||||
version: v0.9.0
|
||||
version: v0.11.0
|
||||
modules:
|
||||
- go.opentelemetry.io/otel/log
|
||||
- go.opentelemetry.io/otel/sdk/log
|
||||
@ -40,3 +40,4 @@ module-sets:
|
||||
- go.opentelemetry.io/otel/schema
|
||||
excluded-modules:
|
||||
- go.opentelemetry.io/otel/internal/tools
|
||||
- go.opentelemetry.io/otel/trace/internal/telemetry/test
|
||||
|
Reference in New Issue
Block a user