-
Notifications
You must be signed in to change notification settings - Fork 244
Expand file tree
/
Copy pathotel_options.go
More file actions
52 lines (43 loc) · 1.58 KB
/
otel_options.go
File metadata and controls
52 lines (43 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
Copyright 2021 The CloudEvents Authors
SPDX-License-Identifier: Apache-2.0
*/
package client
import (
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
cloudevents "github.com/cloudevents/sdk-go/v2"
"github.com/cloudevents/sdk-go/v2/observability"
)
const (
// The value for the `otel.library.name` span attribute
instrumentationName = "github.com/cloudevents/sdk-go/observability/opentelemetry/v2"
)
type OTelObservabilityServiceOption func(*OTelObservabilityService)
// WithSpanAttributesGetter appends the returned attributes from the function to the span.
func WithSpanAttributesGetter(attrGetter func(cloudevents.Event) []attribute.KeyValue) OTelObservabilityServiceOption {
return func(os *OTelObservabilityService) {
if attrGetter != nil {
os.spanAttributesGetter = attrGetter
}
}
}
// WithSpanNameFormatter replaces the default span name with the string returned from the function
func WithSpanNameFormatter(nameFormatter func(cloudevents.Event) string) OTelObservabilityServiceOption {
return func(os *OTelObservabilityService) {
if nameFormatter != nil {
os.spanNameFormatter = nameFormatter
}
}
}
// WithTracerProvider sets the tracer provider to use for creating spans.
func WithTracerProvider(tracerProvider trace.TracerProvider) OTelObservabilityServiceOption {
return func(os *OTelObservabilityService) {
if tracerProvider != nil {
os.traceProvider = tracerProvider
}
}
}
var defaultSpanNameFormatter func(cloudevents.Event) string = func(e cloudevents.Event) string {
return observability.ClientSpanName + "." + e.Context.GetType()
}