You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-08-10 22:31:50 +02:00
chore: enable unused-parameter rule from revive (#7122)
#### Description Enable and fixes [unused-parameter](https://github.com/mgechev/revive/blob/HEAD/RULES_DESCRIPTIONS.md#unused-parameter) rule from revive Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
This commit is contained in:
@@ -181,6 +181,7 @@ linters:
|
|||||||
- fmt.Print
|
- fmt.Print
|
||||||
- fmt.Printf
|
- fmt.Printf
|
||||||
- fmt.Println
|
- fmt.Println
|
||||||
|
- name: unused-parameter
|
||||||
- name: unnecessary-stmt
|
- name: unnecessary-stmt
|
||||||
- name: use-any
|
- name: use-any
|
||||||
- name: useless-break
|
- name: useless-break
|
||||||
|
@@ -16,7 +16,7 @@ type Filter func(KeyValue) bool
|
|||||||
// If keys is empty a deny-all filter is returned.
|
// If keys is empty a deny-all filter is returned.
|
||||||
func NewAllowKeysFilter(keys ...Key) Filter {
|
func NewAllowKeysFilter(keys ...Key) Filter {
|
||||||
if len(keys) == 0 {
|
if len(keys) == 0 {
|
||||||
return func(kv KeyValue) bool { return false }
|
return func(KeyValue) bool { return false }
|
||||||
}
|
}
|
||||||
|
|
||||||
allowed := make(map[Key]struct{}, len(keys))
|
allowed := make(map[Key]struct{}, len(keys))
|
||||||
@@ -35,7 +35,7 @@ func NewAllowKeysFilter(keys ...Key) Filter {
|
|||||||
// If keys is empty an allow-all filter is returned.
|
// If keys is empty an allow-all filter is returned.
|
||||||
func NewDenyKeysFilter(keys ...Key) Filter {
|
func NewDenyKeysFilter(keys ...Key) Filter {
|
||||||
if len(keys) == 0 {
|
if len(keys) == 0 {
|
||||||
return func(kv KeyValue) bool { return true }
|
return func(KeyValue) bool { return true }
|
||||||
}
|
}
|
||||||
|
|
||||||
forbid := make(map[Key]struct{}, len(keys))
|
forbid := make(map[Key]struct{}, len(keys))
|
||||||
|
@@ -214,21 +214,21 @@ func TestFiltering(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "None",
|
name: "None",
|
||||||
in: []attribute.KeyValue{a, b, c},
|
in: []attribute.KeyValue{a, b, c},
|
||||||
filter: func(kv attribute.KeyValue) bool { return false },
|
filter: func(attribute.KeyValue) bool { return false },
|
||||||
kept: nil,
|
kept: nil,
|
||||||
drop: []attribute.KeyValue{a, b, c},
|
drop: []attribute.KeyValue{a, b, c},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "All",
|
name: "All",
|
||||||
in: []attribute.KeyValue{a, b, c},
|
in: []attribute.KeyValue{a, b, c},
|
||||||
filter: func(kv attribute.KeyValue) bool { return true },
|
filter: func(attribute.KeyValue) bool { return true },
|
||||||
kept: []attribute.KeyValue{a, b, c},
|
kept: []attribute.KeyValue{a, b, c},
|
||||||
drop: nil,
|
drop: nil,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Empty",
|
name: "Empty",
|
||||||
in: []attribute.KeyValue{},
|
in: []attribute.KeyValue{},
|
||||||
filter: func(kv attribute.KeyValue) bool { return true },
|
filter: func(attribute.KeyValue) bool { return true },
|
||||||
kept: nil,
|
kept: nil,
|
||||||
drop: nil,
|
drop: nil,
|
||||||
},
|
},
|
||||||
|
@@ -80,7 +80,7 @@ func (s *Span) Annotatef(attributes []octrace.Attribute, format string, a ...any
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddMessageSendEvent adds a message send event to this span.
|
// AddMessageSendEvent adds a message send event to this span.
|
||||||
func (s *Span) AddMessageSendEvent(messageID, uncompressedByteSize, compressedByteSize int64) {
|
func (s *Span) AddMessageSendEvent(_, uncompressedByteSize, compressedByteSize int64) {
|
||||||
s.otelSpan.AddEvent(MessageSendEvent,
|
s.otelSpan.AddEvent(MessageSendEvent,
|
||||||
trace.WithAttributes(
|
trace.WithAttributes(
|
||||||
attribute.KeyValue{
|
attribute.KeyValue{
|
||||||
@@ -95,7 +95,7 @@ func (s *Span) AddMessageSendEvent(messageID, uncompressedByteSize, compressedBy
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddMessageReceiveEvent adds a message receive event to this span.
|
// AddMessageReceiveEvent adds a message receive event to this span.
|
||||||
func (s *Span) AddMessageReceiveEvent(messageID, uncompressedByteSize, compressedByteSize int64) {
|
func (s *Span) AddMessageReceiveEvent(_, uncompressedByteSize, compressedByteSize int64) {
|
||||||
s.otelSpan.AddEvent(MessageReceiveEvent,
|
s.otelSpan.AddEvent(MessageReceiveEvent,
|
||||||
trace.WithAttributes(
|
trace.WithAttributes(
|
||||||
attribute.KeyValue{
|
attribute.KeyValue{
|
||||||
|
@@ -23,7 +23,7 @@ type MetricProducer struct {
|
|||||||
|
|
||||||
// NewMetricProducer returns a metric.Producer that fetches metrics from
|
// NewMetricProducer returns a metric.Producer that fetches metrics from
|
||||||
// OpenCensus.
|
// OpenCensus.
|
||||||
func NewMetricProducer(opts ...MetricOption) *MetricProducer {
|
func NewMetricProducer(...MetricOption) *MetricProducer {
|
||||||
return &MetricProducer{
|
return &MetricProducer{
|
||||||
manager: metricproducer.GlobalManager(),
|
manager: metricproducer.GlobalManager(),
|
||||||
}
|
}
|
||||||
|
@@ -321,10 +321,10 @@ var (
|
|||||||
func NewBridgeTracer() *BridgeTracer {
|
func NewBridgeTracer() *BridgeTracer {
|
||||||
return &BridgeTracer{
|
return &BridgeTracer{
|
||||||
setTracer: bridgeSetTracer{
|
setTracer: bridgeSetTracer{
|
||||||
warningHandler: func(msg string) {},
|
warningHandler: func(string) {},
|
||||||
otelTracer: noopTracer,
|
otelTracer: noopTracer,
|
||||||
},
|
},
|
||||||
warningHandler: func(msg string) {},
|
warningHandler: func(string) {},
|
||||||
propagator: nil,
|
propagator: nil,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -832,12 +832,12 @@ func newTextMapWrapperForInject(carrier any) (*textMapWrapper, error) {
|
|||||||
|
|
||||||
type textMapWriter struct{}
|
type textMapWriter struct{}
|
||||||
|
|
||||||
func (t *textMapWriter) Set(key, value string) {
|
func (t *textMapWriter) Set(string, string) {
|
||||||
// maybe print a warning log.
|
// maybe print a warning log.
|
||||||
}
|
}
|
||||||
|
|
||||||
type textMapReader struct{}
|
type textMapReader struct{}
|
||||||
|
|
||||||
func (t *textMapReader) ForeachKey(handler func(key, val string) error) error {
|
func (t *textMapReader) ForeachKey(func(string, string) error) error {
|
||||||
return nil // maybe print a warning log.
|
return nil // maybe print a warning log.
|
||||||
}
|
}
|
||||||
|
@@ -22,7 +22,7 @@ import (
|
|||||||
|
|
||||||
type testGRPCServer struct{}
|
type testGRPCServer struct{}
|
||||||
|
|
||||||
func (*testGRPCServer) UnaryCall(ctx context.Context, r *testpb.SimpleRequest) (*testpb.SimpleResponse, error) {
|
func (*testGRPCServer) UnaryCall(_ context.Context, r *testpb.SimpleRequest) (*testpb.SimpleResponse, error) {
|
||||||
return &testpb.SimpleResponse{Payload: r.Payload * 2}, nil
|
return &testpb.SimpleResponse{Payload: r.Payload * 2}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -134,7 +134,7 @@ var (
|
|||||||
|
|
||||||
type testTextMapPropagator struct{}
|
type testTextMapPropagator struct{}
|
||||||
|
|
||||||
func (t testTextMapPropagator) Inject(ctx context.Context, carrier propagation.TextMapCarrier) {
|
func (t testTextMapPropagator) Inject(_ context.Context, carrier propagation.TextMapCarrier) {
|
||||||
carrier.Set(testHeader, traceID.String()+":"+spanID.String())
|
carrier.Set(testHeader, traceID.String()+":"+spanID.String())
|
||||||
|
|
||||||
// Test for panic
|
// Test for panic
|
||||||
@@ -370,7 +370,7 @@ type nonDeferWrapperTracer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *nonDeferWrapperTracer) Start(
|
func (t *nonDeferWrapperTracer) Start(
|
||||||
ctx context.Context,
|
_ context.Context,
|
||||||
name string,
|
name string,
|
||||||
opts ...trace.SpanStartOption,
|
opts ...trace.SpanStartOption,
|
||||||
) (context.Context, trace.Span) {
|
) (context.Context, trace.Span) {
|
||||||
@@ -393,7 +393,7 @@ func TestBridgeTracer_StartSpan(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "with wrapper tracer set",
|
name: "with wrapper tracer set",
|
||||||
before: func(t *testing.T, bridge *BridgeTracer) {
|
before: func(_ *testing.T, bridge *BridgeTracer) {
|
||||||
wTracer := NewWrapperTracer(bridge, otel.Tracer("test"))
|
wTracer := NewWrapperTracer(bridge, otel.Tracer("test"))
|
||||||
bridge.SetOpenTelemetryTracer(wTracer)
|
bridge.SetOpenTelemetryTracer(wTracer)
|
||||||
},
|
},
|
||||||
@@ -401,7 +401,7 @@ func TestBridgeTracer_StartSpan(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "with a non-deferred wrapper tracer",
|
name: "with a non-deferred wrapper tracer",
|
||||||
before: func(t *testing.T, bridge *BridgeTracer) {
|
before: func(_ *testing.T, bridge *BridgeTracer) {
|
||||||
wTracer := &nonDeferWrapperTracer{
|
wTracer := &nonDeferWrapperTracer{
|
||||||
NewWrapperTracer(bridge, otel.Tracer("test")),
|
NewWrapperTracer(bridge, otel.Tracer("test")),
|
||||||
}
|
}
|
||||||
|
@@ -128,7 +128,7 @@ func newSimpleTest() *simpleTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *simpleTest) setup(t *testing.T, tracer *mockTracer) {
|
func (st *simpleTest) setup(_ *testing.T, tracer *mockTracer) {
|
||||||
tracer.SpareTraceIDs = append(tracer.SpareTraceIDs, st.traceID)
|
tracer.SpareTraceIDs = append(tracer.SpareTraceIDs, st.traceID)
|
||||||
tracer.SpareSpanIDs = append(tracer.SpareSpanIDs, st.spanIDs...)
|
tracer.SpareSpanIDs = append(tracer.SpareSpanIDs, st.spanIDs...)
|
||||||
}
|
}
|
||||||
@@ -145,7 +145,7 @@ func (st *simpleTest) runOTOtelOT(t *testing.T, ctx context.Context) {
|
|||||||
runOTOtelOT(t, ctx, "simple", st.noop)
|
runOTOtelOT(t, ctx, "simple", st.noop)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *simpleTest) noop(t *testing.T, ctx context.Context) context.Context {
|
func (st *simpleTest) noop(_ *testing.T, ctx context.Context) context.Context {
|
||||||
return ctx
|
return ctx
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,7 +166,7 @@ func newCurrentActiveSpanTest() *currentActiveSpanTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cast *currentActiveSpanTest) setup(t *testing.T, tracer *mockTracer) {
|
func (cast *currentActiveSpanTest) setup(_ *testing.T, tracer *mockTracer) {
|
||||||
tracer.SpareTraceIDs = append(tracer.SpareTraceIDs, cast.traceID)
|
tracer.SpareTraceIDs = append(tracer.SpareTraceIDs, cast.traceID)
|
||||||
tracer.SpareSpanIDs = append(tracer.SpareSpanIDs, cast.spanIDs...)
|
tracer.SpareSpanIDs = append(tracer.SpareSpanIDs, cast.spanIDs...)
|
||||||
|
|
||||||
@@ -221,7 +221,7 @@ func (cast *currentActiveSpanTest) runOTOtelOT(t *testing.T, ctx context.Context
|
|||||||
runOTOtelOT(t, ctx, "cast", cast.recordSpans)
|
runOTOtelOT(t, ctx, "cast", cast.recordSpans)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cast *currentActiveSpanTest) recordSpans(t *testing.T, ctx context.Context) context.Context {
|
func (cast *currentActiveSpanTest) recordSpans(_ *testing.T, ctx context.Context) context.Context {
|
||||||
spanID := trace.SpanContextFromContext(ctx).SpanID()
|
spanID := trace.SpanContextFromContext(ctx).SpanID()
|
||||||
cast.recordedCurrentOtelSpanIDs = append(cast.recordedCurrentOtelSpanIDs, spanID)
|
cast.recordedCurrentOtelSpanIDs = append(cast.recordedCurrentOtelSpanIDs, spanID)
|
||||||
|
|
||||||
@@ -273,14 +273,14 @@ func newContextIntactTest() *contextIntactTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (coin *contextIntactTest) setup(t *testing.T, tracer *mockTracer) {
|
func (coin *contextIntactTest) setup(_ *testing.T, tracer *mockTracer) {
|
||||||
tracer.SpareContextKeyValues = append(tracer.SpareContextKeyValues, coin.contextKeyValues...)
|
tracer.SpareContextKeyValues = append(tracer.SpareContextKeyValues, coin.contextKeyValues...)
|
||||||
|
|
||||||
coin.recordedContextValues = nil
|
coin.recordedContextValues = nil
|
||||||
coin.recordIdx = 0
|
coin.recordIdx = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (coin *contextIntactTest) check(t *testing.T, tracer *mockTracer) {
|
func (coin *contextIntactTest) check(t *testing.T, _ *mockTracer) {
|
||||||
if len(coin.recordedContextValues) != len(coin.contextKeyValues) {
|
if len(coin.recordedContextValues) != len(coin.contextKeyValues) {
|
||||||
t.Errorf(
|
t.Errorf(
|
||||||
"Expected to have %d recorded context values, got %d",
|
"Expected to have %d recorded context values, got %d",
|
||||||
@@ -352,12 +352,12 @@ func newBaggageItemsPreservationTest() *baggageItemsPreservationTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bip *baggageItemsPreservationTest) setup(t *testing.T, tracer *mockTracer) {
|
func (bip *baggageItemsPreservationTest) setup(*testing.T, *mockTracer) {
|
||||||
bip.step = 0
|
bip.step = 0
|
||||||
bip.recordedBaggage = nil
|
bip.recordedBaggage = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bip *baggageItemsPreservationTest) check(t *testing.T, tracer *mockTracer) {
|
func (bip *baggageItemsPreservationTest) check(t *testing.T, _ *mockTracer) {
|
||||||
if len(bip.recordedBaggage) != len(bip.baggageItems) {
|
if len(bip.recordedBaggage) != len(bip.baggageItems) {
|
||||||
t.Errorf("Expected %d recordings, got %d", len(bip.baggageItems), len(bip.recordedBaggage))
|
t.Errorf("Expected %d recordings, got %d", len(bip.baggageItems), len(bip.recordedBaggage))
|
||||||
}
|
}
|
||||||
@@ -450,13 +450,13 @@ func newBaggageInteroperationTest() *baggageInteroperationTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bio *baggageInteroperationTest) setup(t *testing.T, tracer *mockTracer) {
|
func (bio *baggageInteroperationTest) setup(*testing.T, *mockTracer) {
|
||||||
bio.step = 0
|
bio.step = 0
|
||||||
bio.recordedOTBaggage = nil
|
bio.recordedOTBaggage = nil
|
||||||
bio.recordedOtelBaggage = nil
|
bio.recordedOtelBaggage = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bio *baggageInteroperationTest) check(t *testing.T, tracer *mockTracer) {
|
func (bio *baggageInteroperationTest) check(t *testing.T, _ *mockTracer) {
|
||||||
checkBIORecording(t, "OT", bio.baggageItems, bio.recordedOTBaggage)
|
checkBIORecording(t, "OT", bio.baggageItems, bio.recordedOTBaggage)
|
||||||
checkBIORecording(t, "Otel", bio.baggageItems, bio.recordedOtelBaggage)
|
checkBIORecording(t, "Otel", bio.baggageItems, bio.recordedOtelBaggage)
|
||||||
}
|
}
|
||||||
|
@@ -66,7 +66,7 @@ func newMockTracer() *mockTracer {
|
|||||||
// Start returns a new trace span with the given name and options.
|
// Start returns a new trace span with the given name and options.
|
||||||
func (t *mockTracer) Start(
|
func (t *mockTracer) Start(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
name string,
|
_ string,
|
||||||
opts ...trace.SpanStartOption,
|
opts ...trace.SpanStartOption,
|
||||||
) (context.Context, trace.Span) {
|
) (context.Context, trace.Span) {
|
||||||
config := trace.NewSpanStartConfig(opts...)
|
config := trace.NewSpanStartConfig(opts...)
|
||||||
@@ -172,7 +172,7 @@ func (t *mockTracer) getRandTraceID() trace.TraceID {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DeferredContextSetupHook implements the DeferredContextSetupTracerExtension interface.
|
// DeferredContextSetupHook implements the DeferredContextSetupTracerExtension interface.
|
||||||
func (t *mockTracer) DeferredContextSetupHook(ctx context.Context, span trace.Span) context.Context {
|
func (t *mockTracer) DeferredContextSetupHook(ctx context.Context, _ trace.Span) context.Context {
|
||||||
return t.addSpareContextValue(ctx)
|
return t.addSpareContextValue(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -21,7 +21,7 @@ type namedMockTracerProvider struct{ embedded.TracerProvider }
|
|||||||
var _ trace.TracerProvider = (*namedMockTracerProvider)(nil)
|
var _ trace.TracerProvider = (*namedMockTracerProvider)(nil)
|
||||||
|
|
||||||
// Tracer returns the WrapperTracer associated with the WrapperTracerProvider.
|
// Tracer returns the WrapperTracer associated with the WrapperTracerProvider.
|
||||||
func (p *namedMockTracerProvider) Tracer(name string, opts ...trace.TracerOption) trace.Tracer {
|
func (p *namedMockTracerProvider) Tracer(name string, _ ...trace.TracerOption) trace.Tracer {
|
||||||
return &namedMockTracer{
|
return &namedMockTracer{
|
||||||
name: name,
|
name: name,
|
||||||
mockTracer: newMockTracer(),
|
mockTracer: newMockTracer(),
|
||||||
|
@@ -24,7 +24,7 @@ type WrapperTracerProvider struct {
|
|||||||
var _ trace.TracerProvider = (*WrapperTracerProvider)(nil)
|
var _ trace.TracerProvider = (*WrapperTracerProvider)(nil)
|
||||||
|
|
||||||
// Tracer returns the WrapperTracer associated with the WrapperTracerProvider.
|
// Tracer returns the WrapperTracer associated with the WrapperTracerProvider.
|
||||||
func (p *WrapperTracerProvider) Tracer(_ string, _ ...trace.TracerOption) trace.Tracer {
|
func (p *WrapperTracerProvider) Tracer(string, ...trace.TracerOption) trace.Tracer {
|
||||||
return p.wTracer
|
return p.wTracer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -268,7 +268,7 @@ func TestNewClient(t *testing.T) {
|
|||||||
// The gRPC connection created by newClient.
|
// The gRPC connection created by newClient.
|
||||||
conn, err := grpc.NewClient("test", grpc.WithTransportCredentials(insecure.NewCredentials()))
|
conn, err := grpc.NewClient("test", grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
newGRPCClientFn = func(target string, opts ...grpc.DialOption) (*grpc.ClientConn, error) {
|
newGRPCClientFn = func(string, ...grpc.DialOption) (*grpc.ClientConn, error) {
|
||||||
return conn, nil
|
return conn, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -89,6 +89,6 @@ func (e *Exporter) Shutdown(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ForceFlush does nothing. The Exporter holds no state.
|
// ForceFlush does nothing. The Exporter holds no state.
|
||||||
func (e *Exporter) ForceFlush(ctx context.Context) error {
|
func (e *Exporter) ForceFlush(context.Context) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@@ -117,7 +117,7 @@ func TestExporterForceFlush(t *testing.T) {
|
|||||||
assert.NoError(t, e.ForceFlush(ctx), "ForceFlush")
|
assert.NoError(t, e.ForceFlush(ctx), "ForceFlush")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestExporterConcurrentSafe(t *testing.T) {
|
func TestExporterConcurrentSafe(*testing.T) {
|
||||||
e := newExporter(&mockClient{})
|
e := newExporter(&mockClient{})
|
||||||
|
|
||||||
const goroutines = 10
|
const goroutines = 10
|
||||||
|
@@ -58,7 +58,7 @@ func (e *Exporter) Export(ctx context.Context, records []log.Record) error {
|
|||||||
|
|
||||||
// Shutdown shuts down the Exporter. Calls to Export or ForceFlush will perform
|
// Shutdown shuts down the Exporter. Calls to Export or ForceFlush will perform
|
||||||
// no operation after this is called.
|
// no operation after this is called.
|
||||||
func (e *Exporter) Shutdown(ctx context.Context) error {
|
func (e *Exporter) Shutdown(context.Context) error {
|
||||||
if e.stopped.Swap(true) {
|
if e.stopped.Swap(true) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -68,6 +68,6 @@ func (e *Exporter) Shutdown(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ForceFlush does nothing. The Exporter holds no state.
|
// ForceFlush does nothing. The Exporter holds no state.
|
||||||
func (e *Exporter) ForceFlush(ctx context.Context) error {
|
func (e *Exporter) ForceFlush(context.Context) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@@ -21,15 +21,15 @@ type client struct {
|
|||||||
|
|
||||||
var _ otlptrace.Client = &client{}
|
var _ otlptrace.Client = &client{}
|
||||||
|
|
||||||
func (c *client) Start(ctx context.Context) error {
|
func (c *client) Start(context.Context) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *client) Stop(ctx context.Context) error {
|
func (c *client) Stop(context.Context) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *client) UploadTraces(ctx context.Context, protoSpans []*tracepb.ResourceSpans) error {
|
func (c *client) UploadTraces(context.Context, []*tracepb.ResourceSpans) error {
|
||||||
return c.uploadErr
|
return c.uploadErr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -152,6 +152,6 @@ func TestNewConfig(t *testing.T) {
|
|||||||
|
|
||||||
type noopProducer struct{}
|
type noopProducer struct{}
|
||||||
|
|
||||||
func (*noopProducer) Produce(ctx context.Context) ([]metricdata.ScopeMetrics, error) {
|
func (*noopProducer) Produce(context.Context) ([]metricdata.ScopeMetrics, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
@@ -143,7 +143,7 @@ func New(opts ...Option) (*Exporter, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Describe implements prometheus.Collector.
|
// Describe implements prometheus.Collector.
|
||||||
func (c *collector) Describe(ch chan<- *prometheus.Desc) {
|
func (c *collector) Describe(chan<- *prometheus.Desc) {
|
||||||
// The Opentelemetry SDK doesn't have information on which will exist when the collector
|
// The Opentelemetry SDK doesn't have information on which will exist when the collector
|
||||||
// is registered. By returning nothing we are an "unchecked" collector in Prometheus,
|
// is registered. By returning nothing we are an "unchecked" collector in Prometheus,
|
||||||
// and assume responsibility for consistency of the metrics produced.
|
// and assume responsibility for consistency of the metrics produced.
|
||||||
|
@@ -886,7 +886,7 @@ func TestDuplicateMetrics(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "conflict_type_counter_and_updowncounter",
|
name: "conflict_type_counter_and_updowncounter",
|
||||||
recordMetrics: func(ctx context.Context, meterA, meterB otelmetric.Meter) {
|
recordMetrics: func(ctx context.Context, meterA, _ otelmetric.Meter) {
|
||||||
counter, err := meterA.Int64Counter("foo",
|
counter, err := meterA.Int64Counter("foo",
|
||||||
otelmetric.WithUnit("By"),
|
otelmetric.WithUnit("By"),
|
||||||
otelmetric.WithDescription("meter foo"))
|
otelmetric.WithDescription("meter foo"))
|
||||||
@@ -907,7 +907,7 @@ func TestDuplicateMetrics(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "conflict_type_histogram_and_updowncounter",
|
name: "conflict_type_histogram_and_updowncounter",
|
||||||
recordMetrics: func(ctx context.Context, meterA, meterB otelmetric.Meter) {
|
recordMetrics: func(ctx context.Context, meterA, _ otelmetric.Meter) {
|
||||||
fooA, err := meterA.Int64UpDownCounter("foo",
|
fooA, err := meterA.Int64UpDownCounter("foo",
|
||||||
otelmetric.WithUnit("By"),
|
otelmetric.WithUnit("By"),
|
||||||
otelmetric.WithDescription("meter gauge foo"))
|
otelmetric.WithDescription("meter gauge foo"))
|
||||||
|
@@ -83,7 +83,7 @@ func (e *Exporter) ExportSpans(ctx context.Context, spans []trace.ReadOnlySpan)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Shutdown is called to stop the exporter, it performs no action.
|
// Shutdown is called to stop the exporter, it performs no action.
|
||||||
func (e *Exporter) Shutdown(ctx context.Context) error {
|
func (e *Exporter) Shutdown(context.Context) error {
|
||||||
e.stoppedMu.Lock()
|
e.stoppedMu.Lock()
|
||||||
e.stopped = true
|
e.stopped = true
|
||||||
e.stoppedMu.Unlock()
|
e.stoppedMu.Unlock()
|
||||||
|
@@ -44,7 +44,7 @@ func TestListFromContext(t *testing.T) {
|
|||||||
|
|
||||||
func TestContextWithSetHook(t *testing.T) {
|
func TestContextWithSetHook(t *testing.T) {
|
||||||
var called bool
|
var called bool
|
||||||
f := func(ctx context.Context, list List) context.Context {
|
f := func(ctx context.Context, _ List) context.Context {
|
||||||
called = true
|
called = true
|
||||||
return ctx
|
return ctx
|
||||||
}
|
}
|
||||||
@@ -65,7 +65,7 @@ func TestContextWithSetHook(t *testing.T) {
|
|||||||
|
|
||||||
func TestContextWithGetHook(t *testing.T) {
|
func TestContextWithGetHook(t *testing.T) {
|
||||||
var called bool
|
var called bool
|
||||||
f := func(ctx context.Context, list List) List {
|
f := func(_ context.Context, list List) List {
|
||||||
called = true
|
called = true
|
||||||
return list
|
return list
|
||||||
}
|
}
|
||||||
|
@@ -28,7 +28,7 @@ type altMeterProvider struct {
|
|||||||
|
|
||||||
var _ metric.MeterProvider = &altMeterProvider{}
|
var _ metric.MeterProvider = &altMeterProvider{}
|
||||||
|
|
||||||
func (amp *altMeterProvider) Meter(name string, opts ...metric.MeterOption) metric.Meter {
|
func (amp *altMeterProvider) Meter(string, ...metric.MeterOption) metric.Meter {
|
||||||
am := &altMeter{
|
am := &altMeter{
|
||||||
provider: amp,
|
provider: amp,
|
||||||
}
|
}
|
||||||
@@ -126,8 +126,8 @@ func (am *altMeter) Int64Gauge(name string, _ ...metric.Int64GaugeOption) (metri
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (am *altMeter) Int64ObservableCounter(
|
func (am *altMeter) Int64ObservableCounter(
|
||||||
name string,
|
string,
|
||||||
options ...metric.Int64ObservableCounterOption,
|
...metric.Int64ObservableCounterOption,
|
||||||
) (metric.Int64ObservableCounter, error) {
|
) (metric.Int64ObservableCounter, error) {
|
||||||
return &testAiCounter{
|
return &testAiCounter{
|
||||||
meter: am,
|
meter: am,
|
||||||
@@ -135,8 +135,8 @@ func (am *altMeter) Int64ObservableCounter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (am *altMeter) Int64ObservableUpDownCounter(
|
func (am *altMeter) Int64ObservableUpDownCounter(
|
||||||
name string,
|
string,
|
||||||
options ...metric.Int64ObservableUpDownCounterOption,
|
...metric.Int64ObservableUpDownCounterOption,
|
||||||
) (metric.Int64ObservableUpDownCounter, error) {
|
) (metric.Int64ObservableUpDownCounter, error) {
|
||||||
return &testAiUpDownCounter{
|
return &testAiUpDownCounter{
|
||||||
meter: am,
|
meter: am,
|
||||||
@@ -144,8 +144,8 @@ func (am *altMeter) Int64ObservableUpDownCounter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (am *altMeter) Int64ObservableGauge(
|
func (am *altMeter) Int64ObservableGauge(
|
||||||
name string,
|
string,
|
||||||
options ...metric.Int64ObservableGaugeOption,
|
...metric.Int64ObservableGaugeOption,
|
||||||
) (metric.Int64ObservableGauge, error) {
|
) (metric.Int64ObservableGauge, error) {
|
||||||
return &testAiGauge{
|
return &testAiGauge{
|
||||||
meter: am,
|
meter: am,
|
||||||
@@ -165,18 +165,18 @@ func (am *altMeter) Float64UpDownCounter(
|
|||||||
|
|
||||||
func (am *altMeter) Float64Histogram(
|
func (am *altMeter) Float64Histogram(
|
||||||
name string,
|
name string,
|
||||||
options ...metric.Float64HistogramOption,
|
_ ...metric.Float64HistogramOption,
|
||||||
) (metric.Float64Histogram, error) {
|
) (metric.Float64Histogram, error) {
|
||||||
return noop.NewMeterProvider().Meter("noop").Float64Histogram(name)
|
return noop.NewMeterProvider().Meter("noop").Float64Histogram(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (am *altMeter) Float64Gauge(name string, options ...metric.Float64GaugeOption) (metric.Float64Gauge, error) {
|
func (am *altMeter) Float64Gauge(name string, _ ...metric.Float64GaugeOption) (metric.Float64Gauge, error) {
|
||||||
return noop.NewMeterProvider().Meter("noop").Float64Gauge(name)
|
return noop.NewMeterProvider().Meter("noop").Float64Gauge(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (am *altMeter) Float64ObservableCounter(
|
func (am *altMeter) Float64ObservableCounter(
|
||||||
name string,
|
string,
|
||||||
options ...metric.Float64ObservableCounterOption,
|
...metric.Float64ObservableCounterOption,
|
||||||
) (metric.Float64ObservableCounter, error) {
|
) (metric.Float64ObservableCounter, error) {
|
||||||
return &testAfCounter{
|
return &testAfCounter{
|
||||||
meter: am,
|
meter: am,
|
||||||
@@ -184,8 +184,8 @@ func (am *altMeter) Float64ObservableCounter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (am *altMeter) Float64ObservableUpDownCounter(
|
func (am *altMeter) Float64ObservableUpDownCounter(
|
||||||
name string,
|
string,
|
||||||
options ...metric.Float64ObservableUpDownCounterOption,
|
...metric.Float64ObservableUpDownCounterOption,
|
||||||
) (metric.Float64ObservableUpDownCounter, error) {
|
) (metric.Float64ObservableUpDownCounter, error) {
|
||||||
return &testAfUpDownCounter{
|
return &testAfUpDownCounter{
|
||||||
meter: am,
|
meter: am,
|
||||||
@@ -193,8 +193,8 @@ func (am *altMeter) Float64ObservableUpDownCounter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (am *altMeter) Float64ObservableGauge(
|
func (am *altMeter) Float64ObservableGauge(
|
||||||
name string,
|
string,
|
||||||
options ...metric.Float64ObservableGaugeOption,
|
...metric.Float64ObservableGaugeOption,
|
||||||
) (metric.Float64ObservableGauge, error) {
|
) (metric.Float64ObservableGauge, error) {
|
||||||
return &testAfGauge{
|
return &testAfGauge{
|
||||||
meter: am,
|
meter: am,
|
||||||
|
@@ -55,19 +55,19 @@ func testInt64ConcurrentSafe(interact func(int64), setDelegate func(metric.Meter
|
|||||||
func TestAsyncInstrumentSetDelegateConcurrentSafe(t *testing.T) {
|
func TestAsyncInstrumentSetDelegateConcurrentSafe(t *testing.T) {
|
||||||
// Float64 Instruments
|
// Float64 Instruments
|
||||||
t.Run("Float64", func(t *testing.T) {
|
t.Run("Float64", func(t *testing.T) {
|
||||||
t.Run("Counter", func(t *testing.T) {
|
t.Run("Counter", func(*testing.T) {
|
||||||
delegate := &afCounter{}
|
delegate := &afCounter{}
|
||||||
f := func(float64) { _ = delegate.unwrap() }
|
f := func(float64) { _ = delegate.unwrap() }
|
||||||
testFloat64ConcurrentSafe(f, delegate.setDelegate)
|
testFloat64ConcurrentSafe(f, delegate.setDelegate)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("UpDownCounter", func(t *testing.T) {
|
t.Run("UpDownCounter", func(*testing.T) {
|
||||||
delegate := &afUpDownCounter{}
|
delegate := &afUpDownCounter{}
|
||||||
f := func(float64) { _ = delegate.unwrap() }
|
f := func(float64) { _ = delegate.unwrap() }
|
||||||
testFloat64ConcurrentSafe(f, delegate.setDelegate)
|
testFloat64ConcurrentSafe(f, delegate.setDelegate)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Gauge", func(t *testing.T) {
|
t.Run("Gauge", func(*testing.T) {
|
||||||
delegate := &afGauge{}
|
delegate := &afGauge{}
|
||||||
f := func(float64) { _ = delegate.unwrap() }
|
f := func(float64) { _ = delegate.unwrap() }
|
||||||
testFloat64ConcurrentSafe(f, delegate.setDelegate)
|
testFloat64ConcurrentSafe(f, delegate.setDelegate)
|
||||||
@@ -77,19 +77,19 @@ func TestAsyncInstrumentSetDelegateConcurrentSafe(t *testing.T) {
|
|||||||
// Int64 Instruments
|
// Int64 Instruments
|
||||||
|
|
||||||
t.Run("Int64", func(t *testing.T) {
|
t.Run("Int64", func(t *testing.T) {
|
||||||
t.Run("Counter", func(t *testing.T) {
|
t.Run("Counter", func(*testing.T) {
|
||||||
delegate := &aiCounter{}
|
delegate := &aiCounter{}
|
||||||
f := func(int64) { _ = delegate.unwrap() }
|
f := func(int64) { _ = delegate.unwrap() }
|
||||||
testInt64ConcurrentSafe(f, delegate.setDelegate)
|
testInt64ConcurrentSafe(f, delegate.setDelegate)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("UpDownCounter", func(t *testing.T) {
|
t.Run("UpDownCounter", func(*testing.T) {
|
||||||
delegate := &aiUpDownCounter{}
|
delegate := &aiUpDownCounter{}
|
||||||
f := func(int64) { _ = delegate.unwrap() }
|
f := func(int64) { _ = delegate.unwrap() }
|
||||||
testInt64ConcurrentSafe(f, delegate.setDelegate)
|
testInt64ConcurrentSafe(f, delegate.setDelegate)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Gauge", func(t *testing.T) {
|
t.Run("Gauge", func(*testing.T) {
|
||||||
delegate := &aiGauge{}
|
delegate := &aiGauge{}
|
||||||
f := func(int64) { _ = delegate.unwrap() }
|
f := func(int64) { _ = delegate.unwrap() }
|
||||||
testInt64ConcurrentSafe(f, delegate.setDelegate)
|
testInt64ConcurrentSafe(f, delegate.setDelegate)
|
||||||
@@ -99,26 +99,26 @@ func TestAsyncInstrumentSetDelegateConcurrentSafe(t *testing.T) {
|
|||||||
|
|
||||||
func TestSyncInstrumentSetDelegateConcurrentSafe(t *testing.T) {
|
func TestSyncInstrumentSetDelegateConcurrentSafe(t *testing.T) {
|
||||||
// Float64 Instruments
|
// Float64 Instruments
|
||||||
t.Run("Float64", func(t *testing.T) {
|
t.Run("Float64", func(*testing.T) {
|
||||||
t.Run("Counter", func(t *testing.T) {
|
t.Run("Counter", func(*testing.T) {
|
||||||
delegate := &sfCounter{}
|
delegate := &sfCounter{}
|
||||||
f := func(v float64) { delegate.Add(context.Background(), v) }
|
f := func(v float64) { delegate.Add(context.Background(), v) }
|
||||||
testFloat64ConcurrentSafe(f, delegate.setDelegate)
|
testFloat64ConcurrentSafe(f, delegate.setDelegate)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("UpDownCounter", func(t *testing.T) {
|
t.Run("UpDownCounter", func(*testing.T) {
|
||||||
delegate := &sfUpDownCounter{}
|
delegate := &sfUpDownCounter{}
|
||||||
f := func(v float64) { delegate.Add(context.Background(), v) }
|
f := func(v float64) { delegate.Add(context.Background(), v) }
|
||||||
testFloat64ConcurrentSafe(f, delegate.setDelegate)
|
testFloat64ConcurrentSafe(f, delegate.setDelegate)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Histogram", func(t *testing.T) {
|
t.Run("Histogram", func(*testing.T) {
|
||||||
delegate := &sfHistogram{}
|
delegate := &sfHistogram{}
|
||||||
f := func(v float64) { delegate.Record(context.Background(), v) }
|
f := func(v float64) { delegate.Record(context.Background(), v) }
|
||||||
testFloat64ConcurrentSafe(f, delegate.setDelegate)
|
testFloat64ConcurrentSafe(f, delegate.setDelegate)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Gauge", func(t *testing.T) {
|
t.Run("Gauge", func(*testing.T) {
|
||||||
delegate := &sfGauge{}
|
delegate := &sfGauge{}
|
||||||
f := func(v float64) { delegate.Record(context.Background(), v) }
|
f := func(v float64) { delegate.Record(context.Background(), v) }
|
||||||
testFloat64ConcurrentSafe(f, delegate.setDelegate)
|
testFloat64ConcurrentSafe(f, delegate.setDelegate)
|
||||||
@@ -127,26 +127,26 @@ func TestSyncInstrumentSetDelegateConcurrentSafe(t *testing.T) {
|
|||||||
|
|
||||||
// Int64 Instruments
|
// Int64 Instruments
|
||||||
|
|
||||||
t.Run("Int64", func(t *testing.T) {
|
t.Run("Int64", func(*testing.T) {
|
||||||
t.Run("Counter", func(t *testing.T) {
|
t.Run("Counter", func(*testing.T) {
|
||||||
delegate := &siCounter{}
|
delegate := &siCounter{}
|
||||||
f := func(v int64) { delegate.Add(context.Background(), v) }
|
f := func(v int64) { delegate.Add(context.Background(), v) }
|
||||||
testInt64ConcurrentSafe(f, delegate.setDelegate)
|
testInt64ConcurrentSafe(f, delegate.setDelegate)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("UpDownCounter", func(t *testing.T) {
|
t.Run("UpDownCounter", func(*testing.T) {
|
||||||
delegate := &siUpDownCounter{}
|
delegate := &siUpDownCounter{}
|
||||||
f := func(v int64) { delegate.Add(context.Background(), v) }
|
f := func(v int64) { delegate.Add(context.Background(), v) }
|
||||||
testInt64ConcurrentSafe(f, delegate.setDelegate)
|
testInt64ConcurrentSafe(f, delegate.setDelegate)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Histogram", func(t *testing.T) {
|
t.Run("Histogram", func(*testing.T) {
|
||||||
delegate := &siHistogram{}
|
delegate := &siHistogram{}
|
||||||
f := func(v int64) { delegate.Record(context.Background(), v) }
|
f := func(v int64) { delegate.Record(context.Background(), v) }
|
||||||
testInt64ConcurrentSafe(f, delegate.setDelegate)
|
testInt64ConcurrentSafe(f, delegate.setDelegate)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Gauge", func(t *testing.T) {
|
t.Run("Gauge", func(*testing.T) {
|
||||||
delegate := &siGauge{}
|
delegate := &siGauge{}
|
||||||
f := func(v int64) { delegate.Record(context.Background(), v) }
|
f := func(v int64) { delegate.Record(context.Background(), v) }
|
||||||
testInt64ConcurrentSafe(f, delegate.setDelegate)
|
testInt64ConcurrentSafe(f, delegate.setDelegate)
|
||||||
|
@@ -88,7 +88,7 @@ func TestLogLevel(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newBuffLogger(buf *bytes.Buffer, verbosity int) logr.Logger {
|
func newBuffLogger(buf *bytes.Buffer, verbosity int) logr.Logger {
|
||||||
return funcr.New(func(prefix, args string) {
|
return funcr.New(func(_, args string) {
|
||||||
_, _ = buf.WriteString(args)
|
_, _ = buf.WriteString(args)
|
||||||
}, funcr.Options{
|
}, funcr.Options{
|
||||||
Verbosity: verbosity,
|
Verbosity: verbosity,
|
||||||
|
@@ -18,7 +18,7 @@ import (
|
|||||||
"go.opentelemetry.io/otel/metric/noop"
|
"go.opentelemetry.io/otel/metric/noop"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMeterProviderConcurrentSafe(t *testing.T) {
|
func TestMeterProviderConcurrentSafe(*testing.T) {
|
||||||
mp := &meterProvider{}
|
mp := &meterProvider{}
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
finish := make(chan struct{})
|
finish := make(chan struct{})
|
||||||
@@ -39,7 +39,7 @@ func TestMeterProviderConcurrentSafe(t *testing.T) {
|
|||||||
<-done
|
<-done
|
||||||
}
|
}
|
||||||
|
|
||||||
var zeroCallback metric.Callback = func(ctx context.Context, or metric.Observer) error {
|
var zeroCallback metric.Callback = func(context.Context, metric.Observer) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,7 +143,7 @@ func testSetupAllInstrumentTypes(
|
|||||||
_, err = m.Int64ObservableGauge("test_Async_Gauge")
|
_, err = m.Int64ObservableGauge("test_Async_Gauge")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
_, err = m.RegisterCallback(func(ctx context.Context, obs metric.Observer) error {
|
_, err = m.RegisterCallback(func(_ context.Context, obs metric.Observer) error {
|
||||||
obs.ObserveFloat64(afcounter, 3)
|
obs.ObserveFloat64(afcounter, 3)
|
||||||
return nil
|
return nil
|
||||||
}, afcounter)
|
}, afcounter)
|
||||||
|
@@ -16,9 +16,8 @@ type testMeterProvider struct {
|
|||||||
count int
|
count int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *testMeterProvider) Meter(name string, opts ...metric.MeterOption) metric.Meter {
|
func (p *testMeterProvider) Meter(string, ...metric.MeterOption) metric.Meter {
|
||||||
p.count++
|
p.count++
|
||||||
|
|
||||||
return &testMeter{}
|
return &testMeter{}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,105 +45,105 @@ type testMeter struct {
|
|||||||
callbacks []metric.Callback
|
callbacks []metric.Callback
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *testMeter) Int64Counter(name string, options ...metric.Int64CounterOption) (metric.Int64Counter, error) {
|
func (m *testMeter) Int64Counter(string, ...metric.Int64CounterOption) (metric.Int64Counter, error) {
|
||||||
m.siCount++
|
m.siCount++
|
||||||
return &testCountingIntInstrument{}, nil
|
return &testCountingIntInstrument{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *testMeter) Int64UpDownCounter(
|
func (m *testMeter) Int64UpDownCounter(
|
||||||
name string,
|
string,
|
||||||
options ...metric.Int64UpDownCounterOption,
|
...metric.Int64UpDownCounterOption,
|
||||||
) (metric.Int64UpDownCounter, error) {
|
) (metric.Int64UpDownCounter, error) {
|
||||||
m.siUDCount++
|
m.siUDCount++
|
||||||
return &testCountingIntInstrument{}, nil
|
return &testCountingIntInstrument{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *testMeter) Int64Histogram(name string, options ...metric.Int64HistogramOption) (metric.Int64Histogram, error) {
|
func (m *testMeter) Int64Histogram(string, ...metric.Int64HistogramOption) (metric.Int64Histogram, error) {
|
||||||
m.siHist++
|
m.siHist++
|
||||||
return &testCountingIntInstrument{}, nil
|
return &testCountingIntInstrument{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *testMeter) Int64Gauge(name string, options ...metric.Int64GaugeOption) (metric.Int64Gauge, error) {
|
func (m *testMeter) Int64Gauge(string, ...metric.Int64GaugeOption) (metric.Int64Gauge, error) {
|
||||||
m.siGauge++
|
m.siGauge++
|
||||||
return &testCountingIntInstrument{}, nil
|
return &testCountingIntInstrument{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *testMeter) Int64ObservableCounter(
|
func (m *testMeter) Int64ObservableCounter(
|
||||||
name string,
|
string,
|
||||||
options ...metric.Int64ObservableCounterOption,
|
...metric.Int64ObservableCounterOption,
|
||||||
) (metric.Int64ObservableCounter, error) {
|
) (metric.Int64ObservableCounter, error) {
|
||||||
m.aiCount++
|
m.aiCount++
|
||||||
return &testCountingIntInstrument{}, nil
|
return &testCountingIntInstrument{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *testMeter) Int64ObservableUpDownCounter(
|
func (m *testMeter) Int64ObservableUpDownCounter(
|
||||||
name string,
|
string,
|
||||||
options ...metric.Int64ObservableUpDownCounterOption,
|
...metric.Int64ObservableUpDownCounterOption,
|
||||||
) (metric.Int64ObservableUpDownCounter, error) {
|
) (metric.Int64ObservableUpDownCounter, error) {
|
||||||
m.aiUDCount++
|
m.aiUDCount++
|
||||||
return &testCountingIntInstrument{}, nil
|
return &testCountingIntInstrument{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *testMeter) Int64ObservableGauge(
|
func (m *testMeter) Int64ObservableGauge(
|
||||||
name string,
|
string,
|
||||||
options ...metric.Int64ObservableGaugeOption,
|
...metric.Int64ObservableGaugeOption,
|
||||||
) (metric.Int64ObservableGauge, error) {
|
) (metric.Int64ObservableGauge, error) {
|
||||||
m.aiGauge++
|
m.aiGauge++
|
||||||
return &testCountingIntInstrument{}, nil
|
return &testCountingIntInstrument{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *testMeter) Float64Counter(name string, options ...metric.Float64CounterOption) (metric.Float64Counter, error) {
|
func (m *testMeter) Float64Counter(string, ...metric.Float64CounterOption) (metric.Float64Counter, error) {
|
||||||
m.sfCount++
|
m.sfCount++
|
||||||
return &testCountingFloatInstrument{}, nil
|
return &testCountingFloatInstrument{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *testMeter) Float64UpDownCounter(
|
func (m *testMeter) Float64UpDownCounter(
|
||||||
name string,
|
string,
|
||||||
options ...metric.Float64UpDownCounterOption,
|
...metric.Float64UpDownCounterOption,
|
||||||
) (metric.Float64UpDownCounter, error) {
|
) (metric.Float64UpDownCounter, error) {
|
||||||
m.sfUDCount++
|
m.sfUDCount++
|
||||||
return &testCountingFloatInstrument{}, nil
|
return &testCountingFloatInstrument{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *testMeter) Float64Histogram(
|
func (m *testMeter) Float64Histogram(
|
||||||
name string,
|
string,
|
||||||
options ...metric.Float64HistogramOption,
|
...metric.Float64HistogramOption,
|
||||||
) (metric.Float64Histogram, error) {
|
) (metric.Float64Histogram, error) {
|
||||||
m.sfHist++
|
m.sfHist++
|
||||||
return &testCountingFloatInstrument{}, nil
|
return &testCountingFloatInstrument{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *testMeter) Float64Gauge(name string, options ...metric.Float64GaugeOption) (metric.Float64Gauge, error) {
|
func (m *testMeter) Float64Gauge(string, ...metric.Float64GaugeOption) (metric.Float64Gauge, error) {
|
||||||
m.sfGauge++
|
m.sfGauge++
|
||||||
return &testCountingFloatInstrument{}, nil
|
return &testCountingFloatInstrument{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *testMeter) Float64ObservableCounter(
|
func (m *testMeter) Float64ObservableCounter(
|
||||||
name string,
|
string,
|
||||||
options ...metric.Float64ObservableCounterOption,
|
...metric.Float64ObservableCounterOption,
|
||||||
) (metric.Float64ObservableCounter, error) {
|
) (metric.Float64ObservableCounter, error) {
|
||||||
m.afCount++
|
m.afCount++
|
||||||
return &testCountingFloatInstrument{}, nil
|
return &testCountingFloatInstrument{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *testMeter) Float64ObservableUpDownCounter(
|
func (m *testMeter) Float64ObservableUpDownCounter(
|
||||||
name string,
|
string,
|
||||||
options ...metric.Float64ObservableUpDownCounterOption,
|
...metric.Float64ObservableUpDownCounterOption,
|
||||||
) (metric.Float64ObservableUpDownCounter, error) {
|
) (metric.Float64ObservableUpDownCounter, error) {
|
||||||
m.afUDCount++
|
m.afUDCount++
|
||||||
return &testCountingFloatInstrument{}, nil
|
return &testCountingFloatInstrument{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *testMeter) Float64ObservableGauge(
|
func (m *testMeter) Float64ObservableGauge(
|
||||||
name string,
|
string,
|
||||||
options ...metric.Float64ObservableGaugeOption,
|
...metric.Float64ObservableGaugeOption,
|
||||||
) (metric.Float64ObservableGauge, error) {
|
) (metric.Float64ObservableGauge, error) {
|
||||||
m.afGauge++
|
m.afGauge++
|
||||||
return &testCountingFloatInstrument{}, nil
|
return &testCountingFloatInstrument{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterCallback captures the function that will be called during Collect.
|
// RegisterCallback captures the function that will be called during Collect.
|
||||||
func (m *testMeter) RegisterCallback(f metric.Callback, i ...metric.Observable) (metric.Registration, error) {
|
func (m *testMeter) RegisterCallback(f metric.Callback, _ ...metric.Observable) (metric.Registration, error) {
|
||||||
m.callbacks = append(m.callbacks, f)
|
m.callbacks = append(m.callbacks, f)
|
||||||
return testReg{
|
return testReg{
|
||||||
f: func(idx int) func() {
|
f: func(idx int) func() {
|
||||||
@@ -183,14 +182,14 @@ type observationRecorder struct {
|
|||||||
ctx context.Context
|
ctx context.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o observationRecorder) ObserveFloat64(i metric.Float64Observable, value float64, _ ...metric.ObserveOption) {
|
func (o observationRecorder) ObserveFloat64(i metric.Float64Observable, _ float64, _ ...metric.ObserveOption) {
|
||||||
iImpl, ok := i.(*testCountingFloatInstrument)
|
iImpl, ok := i.(*testCountingFloatInstrument)
|
||||||
if ok {
|
if ok {
|
||||||
iImpl.observe()
|
iImpl.observe()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o observationRecorder) ObserveInt64(i metric.Int64Observable, value int64, _ ...metric.ObserveOption) {
|
func (o observationRecorder) ObserveInt64(i metric.Int64Observable, _ int64, _ ...metric.ObserveOption) {
|
||||||
iImpl, ok := i.(*testCountingIntInstrument)
|
iImpl, ok := i.(*testCountingIntInstrument)
|
||||||
if ok {
|
if ok {
|
||||||
iImpl.observe()
|
iImpl.observe()
|
||||||
|
@@ -59,11 +59,11 @@ func TestTraceProviderDelegation(t *testing.T) {
|
|||||||
_, span1 := tracer1.Start(ctx, "span1")
|
_, span1 := tracer1.Start(ctx, "span1")
|
||||||
|
|
||||||
SetTracerProvider(fnTracerProvider{
|
SetTracerProvider(fnTracerProvider{
|
||||||
tracer: func(name string, opts ...trace.TracerOption) trace.Tracer {
|
tracer: func(name string, _ ...trace.TracerOption) trace.Tracer {
|
||||||
spans, ok := expected[name]
|
spans, ok := expected[name]
|
||||||
assert.Truef(t, ok, "invalid tracer: %s", name)
|
assert.Truef(t, ok, "invalid tracer: %s", name)
|
||||||
return fnTracer{
|
return fnTracer{
|
||||||
start: func(ctx context.Context, spanName string, opts ...trace.SpanStartOption) (context.Context, trace.Span) {
|
start: func(ctx context.Context, spanName string, _ ...trace.SpanStartOption) (context.Context, trace.Span) {
|
||||||
if ok {
|
if ok {
|
||||||
if len(spans) == 0 {
|
if len(spans) == 0 {
|
||||||
t.Errorf("unexpected span: %s", spanName)
|
t.Errorf("unexpected span: %s", spanName)
|
||||||
@@ -105,7 +105,7 @@ func TestTraceProviderDelegates(t *testing.T) {
|
|||||||
// Configure it with a spy.
|
// Configure it with a spy.
|
||||||
called := false
|
called := false
|
||||||
SetTracerProvider(fnTracerProvider{
|
SetTracerProvider(fnTracerProvider{
|
||||||
tracer: func(name string, opts ...trace.TracerOption) trace.Tracer {
|
tracer: func(name string, _ ...trace.TracerOption) trace.Tracer {
|
||||||
called = true
|
called = true
|
||||||
assert.Equal(t, "abc", name)
|
assert.Equal(t, "abc", name)
|
||||||
return noop.NewTracerProvider().Tracer("")
|
return noop.NewTracerProvider().Tracer("")
|
||||||
@@ -142,7 +142,7 @@ func TestTraceProviderDelegatesConcurrentSafe(t *testing.T) {
|
|||||||
// Configure it with a spy.
|
// Configure it with a spy.
|
||||||
called := int32(0)
|
called := int32(0)
|
||||||
SetTracerProvider(fnTracerProvider{
|
SetTracerProvider(fnTracerProvider{
|
||||||
tracer: func(name string, opts ...trace.TracerOption) trace.Tracer {
|
tracer: func(name string, _ ...trace.TracerOption) trace.Tracer {
|
||||||
newVal := atomic.AddInt32(&called, 1)
|
newVal := atomic.AddInt32(&called, 1)
|
||||||
assert.Equal(t, "abc", name)
|
assert.Equal(t, "abc", name)
|
||||||
if newVal == 10 {
|
if newVal == 10 {
|
||||||
@@ -186,10 +186,10 @@ func TestTracerDelegatesConcurrentSafe(t *testing.T) {
|
|||||||
// Configure it with a spy.
|
// Configure it with a spy.
|
||||||
called := int32(0)
|
called := int32(0)
|
||||||
SetTracerProvider(fnTracerProvider{
|
SetTracerProvider(fnTracerProvider{
|
||||||
tracer: func(name string, opts ...trace.TracerOption) trace.Tracer {
|
tracer: func(name string, _ ...trace.TracerOption) trace.Tracer {
|
||||||
assert.Equal(t, "abc", name)
|
assert.Equal(t, "abc", name)
|
||||||
return fnTracer{
|
return fnTracer{
|
||||||
start: func(ctx context.Context, spanName string, opts ...trace.SpanStartOption) (context.Context, trace.Span) {
|
start: func(ctx context.Context, spanName string, _ ...trace.SpanStartOption) (context.Context, trace.Span) {
|
||||||
newVal := atomic.AddInt32(&called, 1)
|
newVal := atomic.AddInt32(&called, 1)
|
||||||
assert.Equal(t, "name", spanName)
|
assert.Equal(t, "name", spanName)
|
||||||
if newVal == 10 {
|
if newVal == 10 {
|
||||||
@@ -218,7 +218,7 @@ func TestTraceProviderDelegatesSameInstance(t *testing.T) {
|
|||||||
assert.Same(t, tracer, gtp.Tracer("abc", trace.WithInstrumentationVersion("xyz")))
|
assert.Same(t, tracer, gtp.Tracer("abc", trace.WithInstrumentationVersion("xyz")))
|
||||||
|
|
||||||
SetTracerProvider(fnTracerProvider{
|
SetTracerProvider(fnTracerProvider{
|
||||||
tracer: func(name string, opts ...trace.TracerOption) trace.Tracer {
|
tracer: func(string, ...trace.TracerOption) trace.Tracer {
|
||||||
return noop.NewTracerProvider().Tracer("")
|
return noop.NewTracerProvider().Tracer("")
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@@ -16,7 +16,7 @@ import (
|
|||||||
"go.opentelemetry.io/otel/log/noop"
|
"go.opentelemetry.io/otel/log/noop"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLoggerProviderConcurrentSafe(t *testing.T) {
|
func TestLoggerProviderConcurrentSafe(*testing.T) {
|
||||||
p := &loggerProvider{}
|
p := &loggerProvider{}
|
||||||
|
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
@@ -41,7 +41,7 @@ func TestLoggerProviderConcurrentSafe(t *testing.T) {
|
|||||||
<-done
|
<-done
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLoggerConcurrentSafe(t *testing.T) {
|
func TestLoggerConcurrentSafe(*testing.T) {
|
||||||
l := &logger{}
|
l := &logger{}
|
||||||
|
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
|
@@ -149,7 +149,7 @@ func TestRecorderLoggerEmitAndReset(t *testing.T) {
|
|||||||
assert.Equal(t, want, got)
|
assert.Equal(t, want, got)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRecorderConcurrentSafe(t *testing.T) {
|
func TestRecorderConcurrentSafe(*testing.T) {
|
||||||
const goRoutineN = 10
|
const goRoutineN = 10
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
|
@@ -35,7 +35,7 @@ func TestFloat64ObservableConfiguration(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cback := func(ctx context.Context, obsrv Float64Observer) error {
|
cback := func(_ context.Context, obsrv Float64Observer) error {
|
||||||
obsrv.Observe(token)
|
obsrv.Observe(token)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@@ -35,7 +35,7 @@ func TestInt64ObservableConfiguration(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cback := func(ctx context.Context, obsrv Int64Observer) error {
|
cback := func(_ context.Context, obsrv Int64Observer) error {
|
||||||
obsrv.Observe(token)
|
obsrv.Observe(token)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@@ -110,7 +110,7 @@ func ExampleMeter_counter() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/", func(_ http.ResponseWriter, r *http.Request) {
|
||||||
apiCounter.Add(r.Context(), 1)
|
apiCounter.Add(r.Context(), 1)
|
||||||
|
|
||||||
// do some work in an API call
|
// do some work in an API call
|
||||||
@@ -195,7 +195,7 @@ func ExampleMeter_histogram() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/", func(_ http.ResponseWriter, r *http.Request) {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
|
|
||||||
// do some work in an API call
|
// do some work in an API call
|
||||||
@@ -231,7 +231,7 @@ func ExampleMeter_observableCounter() {
|
|||||||
func ExampleMeter_observableUpDownCounter() {
|
func ExampleMeter_observableUpDownCounter() {
|
||||||
// The function registers asynchronous metrics for the provided db.
|
// The function registers asynchronous metrics for the provided db.
|
||||||
// Make sure to unregister metric.Registration before closing the provided db.
|
// Make sure to unregister metric.Registration before closing the provided db.
|
||||||
_ = func(db *sql.DB, meter metric.Meter, poolName string) (metric.Registration, error) {
|
_ = func(db *sql.DB, meter metric.Meter, _ string) (metric.Registration, error) {
|
||||||
m, err := meter.Int64ObservableUpDownCounter(
|
m, err := meter.Int64ObservableUpDownCounter(
|
||||||
"db.client.connections.max",
|
"db.client.connections.max",
|
||||||
metric.WithDescription("The maximum number of open connections allowed."),
|
metric.WithDescription("The maximum number of open connections allowed."),
|
||||||
@@ -301,7 +301,7 @@ func ExampleMeter_attributes() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/", func(_ http.ResponseWriter, r *http.Request) {
|
||||||
// do some work in an API call and set the response HTTP status code
|
// do some work in an API call and set the response HTTP status code
|
||||||
statusCode := http.StatusOK
|
statusCode := http.StatusOK
|
||||||
|
|
||||||
|
@@ -90,7 +90,7 @@ func testConfAttr(newConf func(...MeasurementOption) attrConf) func(t *testing.T
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWithAttributesConcurrentSafe(t *testing.T) {
|
func TestWithAttributesConcurrentSafe(*testing.T) {
|
||||||
attrs := []attribute.KeyValue{
|
attrs := []attribute.KeyValue{
|
||||||
attribute.String("user", "Alice"),
|
attribute.String("user", "Alice"),
|
||||||
attribute.Bool("admin", true),
|
attribute.Bool("admin", true),
|
||||||
|
@@ -17,7 +17,7 @@ type testMeterProvider struct{ embedded.MeterProvider }
|
|||||||
|
|
||||||
var _ metric.MeterProvider = &testMeterProvider{}
|
var _ metric.MeterProvider = &testMeterProvider{}
|
||||||
|
|
||||||
func (*testMeterProvider) Meter(_ string, _ ...metric.MeterOption) metric.Meter {
|
func (*testMeterProvider) Meter(string, ...metric.MeterOption) metric.Meter {
|
||||||
return noop.NewMeterProvider().Meter("")
|
return noop.NewMeterProvider().Meter("")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -32,11 +32,11 @@ type propagator struct {
|
|||||||
Name string
|
Name string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p propagator) Inject(ctx context.Context, carrier propagation.TextMapCarrier) {
|
func (p propagator) Inject(_ context.Context, carrier propagation.TextMapCarrier) {
|
||||||
carrier.Set(p.Name, "")
|
carrier.Set(p.Name, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p propagator) Extract(ctx context.Context, carrier propagation.TextMapCarrier) context.Context {
|
func (p propagator) Extract(ctx context.Context, _ propagation.TextMapCarrier) context.Context {
|
||||||
v := ctx.Value(ctxKey)
|
v := ctx.Value(ctxKey)
|
||||||
if v == nil {
|
if v == nil {
|
||||||
ctx = context.WithValue(ctx, ctxKey, []string{p.Name})
|
ctx = context.WithValue(ctx, ctxKey, []string{p.Name})
|
||||||
|
@@ -48,7 +48,7 @@ type outOfThinAirPropagator struct {
|
|||||||
|
|
||||||
var _ propagation.TextMapPropagator = outOfThinAirPropagator{}
|
var _ propagation.TextMapPropagator = outOfThinAirPropagator{}
|
||||||
|
|
||||||
func (p outOfThinAirPropagator) Extract(ctx context.Context, carrier propagation.TextMapCarrier) context.Context {
|
func (p outOfThinAirPropagator) Extract(ctx context.Context, _ propagation.TextMapCarrier) context.Context {
|
||||||
sc := trace.NewSpanContext(trace.SpanContextConfig{
|
sc := trace.NewSpanContext(trace.SpanContextConfig{
|
||||||
TraceID: traceID,
|
TraceID: traceID,
|
||||||
SpanID: spanID,
|
SpanID: spanID,
|
||||||
@@ -72,11 +72,11 @@ func (nilCarrier) Keys() []string {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nilCarrier) Get(key string) string {
|
func (nilCarrier) Get(string) string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nilCarrier) Set(key, value string) {}
|
func (nilCarrier) Set(string, string) {}
|
||||||
|
|
||||||
func TestMultiplePropagators(t *testing.T) {
|
func TestMultiplePropagators(t *testing.T) {
|
||||||
ootaProp := outOfThinAirPropagator{t: t}
|
ootaProp := outOfThinAirPropagator{t: t}
|
||||||
|
@@ -128,7 +128,7 @@ func BenchmarkProcessor(b *testing.B) {
|
|||||||
|
|
||||||
type timestampProcessor struct{}
|
type timestampProcessor struct{}
|
||||||
|
|
||||||
func (p timestampProcessor) OnEmit(ctx context.Context, r *Record) error {
|
func (p timestampProcessor) OnEmit(_ context.Context, r *Record) error {
|
||||||
r.SetObservedTimestamp(time.Date(1988, time.November, 17, 0, 0, 0, 0, time.UTC))
|
r.SetObservedTimestamp(time.Date(1988, time.November, 17, 0, 0, 0, 0, time.UTC))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -137,17 +137,17 @@ func (p timestampProcessor) Enabled(context.Context, Record) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p timestampProcessor) Shutdown(ctx context.Context) error {
|
func (p timestampProcessor) Shutdown(context.Context) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p timestampProcessor) ForceFlush(ctx context.Context) error {
|
func (p timestampProcessor) ForceFlush(context.Context) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type attrAddProcessor struct{}
|
type attrAddProcessor struct{}
|
||||||
|
|
||||||
func (p attrAddProcessor) OnEmit(ctx context.Context, r *Record) error {
|
func (p attrAddProcessor) OnEmit(_ context.Context, r *Record) error {
|
||||||
r.AddAttributes(log.String("add", "me"))
|
r.AddAttributes(log.String("add", "me"))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -156,17 +156,17 @@ func (p attrAddProcessor) Enabled(context.Context, Record) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p attrAddProcessor) Shutdown(ctx context.Context) error {
|
func (p attrAddProcessor) Shutdown(context.Context) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p attrAddProcessor) ForceFlush(ctx context.Context) error {
|
func (p attrAddProcessor) ForceFlush(context.Context) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type attrSetDecorator struct{}
|
type attrSetDecorator struct{}
|
||||||
|
|
||||||
func (p attrSetDecorator) OnEmit(ctx context.Context, r *Record) error {
|
func (p attrSetDecorator) OnEmit(_ context.Context, r *Record) error {
|
||||||
r.SetAttributes(log.String("replace", "me"))
|
r.SetAttributes(log.String("replace", "me"))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -175,10 +175,10 @@ func (p attrSetDecorator) Enabled(context.Context, Record) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p attrSetDecorator) Shutdown(ctx context.Context) error {
|
func (p attrSetDecorator) Shutdown(context.Context) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p attrSetDecorator) ForceFlush(ctx context.Context) error {
|
func (p attrSetDecorator) ForceFlush(context.Context) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@@ -135,7 +135,7 @@ type RedactTokensProcessor struct{}
|
|||||||
|
|
||||||
// OnEmit redacts values from attributes containing "token" in the key
|
// OnEmit redacts values from attributes containing "token" in the key
|
||||||
// by replacing them with a REDACTED value.
|
// by replacing them with a REDACTED value.
|
||||||
func (p *RedactTokensProcessor) OnEmit(ctx context.Context, record *log.Record) error {
|
func (p *RedactTokensProcessor) OnEmit(_ context.Context, record *log.Record) error {
|
||||||
record.WalkAttributes(func(kv logapi.KeyValue) bool {
|
record.WalkAttributes(func(kv logapi.KeyValue) bool {
|
||||||
if strings.Contains(strings.ToLower(kv.Key), "token") {
|
if strings.Contains(strings.ToLower(kv.Key), "token") {
|
||||||
record.AddAttributes(logapi.String(kv.Key, "REDACTED"))
|
record.AddAttributes(logapi.String(kv.Key, "REDACTED"))
|
||||||
@@ -146,11 +146,11 @@ func (p *RedactTokensProcessor) OnEmit(ctx context.Context, record *log.Record)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Shutdown returns nil.
|
// Shutdown returns nil.
|
||||||
func (p *RedactTokensProcessor) Shutdown(ctx context.Context) error {
|
func (p *RedactTokensProcessor) Shutdown(context.Context) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ForceFlush returns nil.
|
// ForceFlush returns nil.
|
||||||
func (p *RedactTokensProcessor) ForceFlush(ctx context.Context) error {
|
func (p *RedactTokensProcessor) ForceFlush(context.Context) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@@ -112,7 +112,7 @@ func (e *testExporter) Stop() {
|
|||||||
<-e.done
|
<-e.done
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *testExporter) Shutdown(ctx context.Context) error {
|
func (e *testExporter) Shutdown(context.Context) error {
|
||||||
atomic.AddInt32(e.shutdownN, 1)
|
atomic.AddInt32(e.shutdownN, 1)
|
||||||
return e.Err
|
return e.Err
|
||||||
}
|
}
|
||||||
@@ -121,7 +121,7 @@ func (e *testExporter) ShutdownN() int {
|
|||||||
return int(atomic.LoadInt32(e.shutdownN))
|
return int(atomic.LoadInt32(e.shutdownN))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *testExporter) ForceFlush(ctx context.Context) error {
|
func (e *testExporter) ForceFlush(context.Context) error {
|
||||||
atomic.AddInt32(e.forceFlushN, 1)
|
atomic.AddInt32(e.forceFlushN, 1)
|
||||||
return e.Err
|
return e.Err
|
||||||
}
|
}
|
||||||
@@ -382,7 +382,7 @@ func TestBufferExporter(t *testing.T) {
|
|||||||
defer func(orig otel.ErrorHandler) {
|
defer func(orig otel.ErrorHandler) {
|
||||||
otel.SetErrorHandler(orig)
|
otel.SetErrorHandler(orig)
|
||||||
}(otel.GetErrorHandler())
|
}(otel.GetErrorHandler())
|
||||||
handler := otel.ErrorHandlerFunc(func(err error) {})
|
handler := otel.ErrorHandlerFunc(func(error) {})
|
||||||
otel.SetErrorHandler(handler)
|
otel.SetErrorHandler(handler)
|
||||||
|
|
||||||
exp := newTestExporter(assert.AnError)
|
exp := newTestExporter(assert.AnError)
|
||||||
|
@@ -40,7 +40,7 @@ var _ log.Exporter = exporter{}
|
|||||||
|
|
||||||
type exporter struct{ io.Writer }
|
type exporter struct{ io.Writer }
|
||||||
|
|
||||||
func (e exporter) Export(ctx context.Context, records []log.Record) error {
|
func (e exporter) Export(_ context.Context, records []log.Record) error {
|
||||||
for i, r := range records {
|
for i, r := range records {
|
||||||
if i != 0 {
|
if i != 0 {
|
||||||
if _, err := e.Write([]byte("\n")); err != nil {
|
if _, err := e.Write([]byte("\n")); err != nil {
|
||||||
|
@@ -40,7 +40,7 @@ func newProcessor(name string) *processor {
|
|||||||
return &processor{Name: name}
|
return &processor{Name: name}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *processor) OnEmit(ctx context.Context, r *Record) error {
|
func (p *processor) OnEmit(_ context.Context, r *Record) error {
|
||||||
if p.Err != nil {
|
if p.Err != nil {
|
||||||
return p.Err
|
return p.Err
|
||||||
}
|
}
|
||||||
@@ -248,7 +248,7 @@ func TestWithResource(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLoggerProviderConcurrentSafe(t *testing.T) {
|
func TestLoggerProviderConcurrentSafe(*testing.T) {
|
||||||
const goRoutineN = 10
|
const goRoutineN = 10
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
|
@@ -96,7 +96,7 @@ func TestSimpleProcessorEmpty(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSimpleProcessorConcurrentSafe(t *testing.T) {
|
func TestSimpleProcessorConcurrentSafe(*testing.T) {
|
||||||
const goRoutineN = 10
|
const goRoutineN = 10
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
|
@@ -66,11 +66,11 @@ func TestConfigReaderSignalsEmpty(t *testing.T) {
|
|||||||
func TestConfigReaderSignalsForwarded(t *testing.T) {
|
func TestConfigReaderSignalsForwarded(t *testing.T) {
|
||||||
var flush, sdown int
|
var flush, sdown int
|
||||||
r := &reader{
|
r := &reader{
|
||||||
forceFlushFunc: func(ctx context.Context) error {
|
forceFlushFunc: func(context.Context) error {
|
||||||
flush++
|
flush++
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
shutdownFunc: func(ctx context.Context) error {
|
shutdownFunc: func(context.Context) error {
|
||||||
sdown++
|
sdown++
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
@@ -93,8 +93,8 @@ func TestConfigReaderSignalsForwarded(t *testing.T) {
|
|||||||
|
|
||||||
func TestConfigReaderSignalsForwardedErrors(t *testing.T) {
|
func TestConfigReaderSignalsForwardedErrors(t *testing.T) {
|
||||||
r := &reader{
|
r := &reader{
|
||||||
forceFlushFunc: func(ctx context.Context) error { return assert.AnError },
|
forceFlushFunc: func(context.Context) error { return assert.AnError },
|
||||||
shutdownFunc: func(ctx context.Context) error { return assert.AnError },
|
shutdownFunc: func(context.Context) error { return assert.AnError },
|
||||||
}
|
}
|
||||||
c := newConfig([]Option{WithReader(r)})
|
c := newConfig([]Option{WithReader(r)})
|
||||||
f, s := c.readerSignals()
|
f, s := c.readerSignals()
|
||||||
@@ -115,9 +115,9 @@ func TestUnifyMultiError(t *testing.T) {
|
|||||||
e2 = errors.New("2")
|
e2 = errors.New("2")
|
||||||
)
|
)
|
||||||
err := unify([]func(context.Context) error{
|
err := unify([]func(context.Context) error{
|
||||||
func(ctx context.Context) error { return e0 },
|
func(context.Context) error { return e0 },
|
||||||
func(ctx context.Context) error { return e1 },
|
func(context.Context) error { return e1 },
|
||||||
func(ctx context.Context) error { return e2 },
|
func(context.Context) error { return e2 },
|
||||||
})(context.Background())
|
})(context.Background())
|
||||||
assert.ErrorIs(t, err, e0)
|
assert.ErrorIs(t, err, e0)
|
||||||
assert.ErrorIs(t, err, e1)
|
assert.ErrorIs(t, err, e1)
|
||||||
|
@@ -24,11 +24,11 @@ func TraceBasedFilter(ctx context.Context) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AlwaysOnFilter is a [Filter] that always offers measurements.
|
// AlwaysOnFilter is a [Filter] that always offers measurements.
|
||||||
func AlwaysOnFilter(ctx context.Context) bool {
|
func AlwaysOnFilter(context.Context) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// AlwaysOffFilter is a [Filter] that never offers measurements.
|
// AlwaysOffFilter is a [Filter] that never offers measurements.
|
||||||
func AlwaysOffFilter(ctx context.Context) bool {
|
func AlwaysOffFilter(context.Context) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@@ -14,7 +14,7 @@ import (
|
|||||||
|
|
||||||
// FixedSizeReservoirProvider returns a provider of [FixedSizeReservoir].
|
// FixedSizeReservoirProvider returns a provider of [FixedSizeReservoir].
|
||||||
func FixedSizeReservoirProvider(k int) ReservoirProvider {
|
func FixedSizeReservoirProvider(k int) ReservoirProvider {
|
||||||
return func(_ attribute.Set) Reservoir {
|
return func(attribute.Set) Reservoir {
|
||||||
return NewFixedSizeReservoir(k)
|
return NewFixedSizeReservoir(k)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,7 +16,7 @@ import (
|
|||||||
func HistogramReservoirProvider(bounds []float64) ReservoirProvider {
|
func HistogramReservoirProvider(bounds []float64) ReservoirProvider {
|
||||||
cp := slices.Clone(bounds)
|
cp := slices.Clone(bounds)
|
||||||
slices.Sort(cp)
|
slices.Sort(cp)
|
||||||
return func(_ attribute.Set) Reservoir {
|
return func(attribute.Set) Reservoir {
|
||||||
return NewHistogramReservoir(cp)
|
return NewHistogramReservoir(cp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -204,7 +204,7 @@ func (i *int64Inst) Record(ctx context.Context, val int64, opts ...metric.Record
|
|||||||
i.aggregate(ctx, val, c.Attributes())
|
i.aggregate(ctx, val, c.Attributes())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *int64Inst) Enabled(_ context.Context) bool {
|
func (i *int64Inst) Enabled(context.Context) bool {
|
||||||
return len(i.measures) != 0
|
return len(i.measures) != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -245,7 +245,7 @@ func (i *float64Inst) Record(ctx context.Context, val float64, opts ...metric.Re
|
|||||||
i.aggregate(ctx, val, c.Attributes())
|
i.aggregate(ctx, val, c.Attributes())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *float64Inst) Enabled(_ context.Context) bool {
|
func (i *float64Inst) Enabled(context.Context) bool {
|
||||||
return len(i.measures) != 0
|
return len(i.measures) != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -102,7 +102,7 @@ func TestManualReaderCollect(t *testing.T) {
|
|||||||
// Ensure the pipeline has a callback setup
|
// Ensure the pipeline has a callback setup
|
||||||
testM, err := meter.Int64ObservableCounter("test")
|
testM, err := meter.Int64ObservableCounter("test")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
_, err = meter.RegisterCallback(func(_ context.Context, o metric.Observer) error {
|
_, err = meter.RegisterCallback(func(context.Context, metric.Observer) error {
|
||||||
return nil
|
return nil
|
||||||
}, testM)
|
}, testM)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
@@ -31,7 +31,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// A meter should be able to make instruments concurrently.
|
// A meter should be able to make instruments concurrently.
|
||||||
func TestMeterInstrumentConcurrentSafe(t *testing.T) {
|
func TestMeterInstrumentConcurrentSafe(*testing.T) {
|
||||||
wg := &sync.WaitGroup{}
|
wg := &sync.WaitGroup{}
|
||||||
wg.Add(12)
|
wg.Add(12)
|
||||||
|
|
||||||
@@ -92,7 +92,7 @@ func TestMeterInstrumentConcurrentSafe(t *testing.T) {
|
|||||||
var emptyCallback metric.Callback = func(context.Context, metric.Observer) error { return nil }
|
var emptyCallback metric.Callback = func(context.Context, metric.Observer) error { return nil }
|
||||||
|
|
||||||
// A Meter Should be able register Callbacks Concurrently.
|
// A Meter Should be able register Callbacks Concurrently.
|
||||||
func TestMeterCallbackCreationConcurrency(t *testing.T) {
|
func TestMeterCallbackCreationConcurrency(*testing.T) {
|
||||||
wg := &sync.WaitGroup{}
|
wg := &sync.WaitGroup{}
|
||||||
wg.Add(2)
|
wg.Add(2)
|
||||||
|
|
||||||
@@ -1368,7 +1368,7 @@ func testAttributeFilter(temporality metricdata.Temporality) func(*testing.T) {
|
|||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "ObservableFloat64Counter",
|
name: "ObservableFloat64Counter",
|
||||||
register: func(t *testing.T, mtr metric.Meter) error {
|
register: func(_ *testing.T, mtr metric.Meter) error {
|
||||||
ctr, err := mtr.Float64ObservableCounter("afcounter")
|
ctr, err := mtr.Float64ObservableCounter("afcounter")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -1394,7 +1394,7 @@ func testAttributeFilter(temporality metricdata.Temporality) func(*testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "ObservableFloat64UpDownCounter",
|
name: "ObservableFloat64UpDownCounter",
|
||||||
register: func(t *testing.T, mtr metric.Meter) error {
|
register: func(_ *testing.T, mtr metric.Meter) error {
|
||||||
ctr, err := mtr.Float64ObservableUpDownCounter("afupdowncounter")
|
ctr, err := mtr.Float64ObservableUpDownCounter("afupdowncounter")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -1423,7 +1423,7 @@ func testAttributeFilter(temporality metricdata.Temporality) func(*testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "ObservableFloat64Gauge",
|
name: "ObservableFloat64Gauge",
|
||||||
register: func(t *testing.T, mtr metric.Meter) error {
|
register: func(_ *testing.T, mtr metric.Meter) error {
|
||||||
ctr, err := mtr.Float64ObservableGauge("afgauge")
|
ctr, err := mtr.Float64ObservableGauge("afgauge")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -1446,7 +1446,7 @@ func testAttributeFilter(temporality metricdata.Temporality) func(*testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "ObservableInt64Counter",
|
name: "ObservableInt64Counter",
|
||||||
register: func(t *testing.T, mtr metric.Meter) error {
|
register: func(_ *testing.T, mtr metric.Meter) error {
|
||||||
ctr, err := mtr.Int64ObservableCounter("aicounter")
|
ctr, err := mtr.Int64ObservableCounter("aicounter")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -1472,7 +1472,7 @@ func testAttributeFilter(temporality metricdata.Temporality) func(*testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "ObservableInt64UpDownCounter",
|
name: "ObservableInt64UpDownCounter",
|
||||||
register: func(t *testing.T, mtr metric.Meter) error {
|
register: func(_ *testing.T, mtr metric.Meter) error {
|
||||||
ctr, err := mtr.Int64ObservableUpDownCounter("aiupdowncounter")
|
ctr, err := mtr.Int64ObservableUpDownCounter("aiupdowncounter")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -1498,7 +1498,7 @@ func testAttributeFilter(temporality metricdata.Temporality) func(*testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "ObservableInt64Gauge",
|
name: "ObservableInt64Gauge",
|
||||||
register: func(t *testing.T, mtr metric.Meter) error {
|
register: func(_ *testing.T, mtr metric.Meter) error {
|
||||||
ctr, err := mtr.Int64ObservableGauge("aigauge")
|
ctr, err := mtr.Int64ObservableGauge("aigauge")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -1521,7 +1521,7 @@ func testAttributeFilter(temporality metricdata.Temporality) func(*testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "SyncFloat64Counter",
|
name: "SyncFloat64Counter",
|
||||||
register: func(t *testing.T, mtr metric.Meter) error {
|
register: func(_ *testing.T, mtr metric.Meter) error {
|
||||||
ctr, err := mtr.Float64Counter("sfcounter")
|
ctr, err := mtr.Float64Counter("sfcounter")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -1544,7 +1544,7 @@ func testAttributeFilter(temporality metricdata.Temporality) func(*testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "SyncFloat64UpDownCounter",
|
name: "SyncFloat64UpDownCounter",
|
||||||
register: func(t *testing.T, mtr metric.Meter) error {
|
register: func(_ *testing.T, mtr metric.Meter) error {
|
||||||
ctr, err := mtr.Float64UpDownCounter("sfupdowncounter")
|
ctr, err := mtr.Float64UpDownCounter("sfupdowncounter")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -1567,7 +1567,7 @@ func testAttributeFilter(temporality metricdata.Temporality) func(*testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "SyncFloat64Histogram",
|
name: "SyncFloat64Histogram",
|
||||||
register: func(t *testing.T, mtr metric.Meter) error {
|
register: func(_ *testing.T, mtr metric.Meter) error {
|
||||||
ctr, err := mtr.Float64Histogram("sfhistogram")
|
ctr, err := mtr.Float64Histogram("sfhistogram")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -1600,7 +1600,7 @@ func testAttributeFilter(temporality metricdata.Temporality) func(*testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "SyncInt64Counter",
|
name: "SyncInt64Counter",
|
||||||
register: func(t *testing.T, mtr metric.Meter) error {
|
register: func(_ *testing.T, mtr metric.Meter) error {
|
||||||
ctr, err := mtr.Int64Counter("sicounter")
|
ctr, err := mtr.Int64Counter("sicounter")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -1623,7 +1623,7 @@ func testAttributeFilter(temporality metricdata.Temporality) func(*testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "SyncInt64UpDownCounter",
|
name: "SyncInt64UpDownCounter",
|
||||||
register: func(t *testing.T, mtr metric.Meter) error {
|
register: func(_ *testing.T, mtr metric.Meter) error {
|
||||||
ctr, err := mtr.Int64UpDownCounter("siupdowncounter")
|
ctr, err := mtr.Int64UpDownCounter("siupdowncounter")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -1646,7 +1646,7 @@ func testAttributeFilter(temporality metricdata.Temporality) func(*testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "SyncInt64Histogram",
|
name: "SyncInt64Histogram",
|
||||||
register: func(t *testing.T, mtr metric.Meter) error {
|
register: func(_ *testing.T, mtr metric.Meter) error {
|
||||||
ctr, err := mtr.Int64Histogram("sihistogram")
|
ctr, err := mtr.Int64Histogram("sihistogram")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -2127,7 +2127,7 @@ func TestMalformedSelectors(t *testing.T) {
|
|||||||
sfHistogram, err := meter.Float64Histogram("sync.float64.histogram")
|
sfHistogram, err := meter.Float64Histogram("sync.float64.histogram")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
callback := func(ctx context.Context, obs metric.Observer) error {
|
callback := func(_ context.Context, obs metric.Observer) error {
|
||||||
obs.ObserveInt64(aiCounter, 1)
|
obs.ObserveInt64(aiCounter, 1)
|
||||||
obs.ObserveInt64(aiUpDownCounter, 1)
|
obs.ObserveInt64(aiUpDownCounter, 1)
|
||||||
obs.ObserveInt64(aiGauge, 1)
|
obs.ObserveInt64(aiGauge, 1)
|
||||||
@@ -2274,7 +2274,7 @@ func TestObservableDropAggregation(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "drop all metrics",
|
name: "drop all metrics",
|
||||||
views: []View{
|
views: []View{
|
||||||
func(i Instrument) (Stream, bool) {
|
func(Instrument) (Stream, bool) {
|
||||||
return Stream{Aggregation: AggregationDrop{}}, true
|
return Stream{Aggregation: AggregationDrop{}}, true
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -2393,7 +2393,7 @@ func TestObservableDropAggregation(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
_, err = meter.RegisterCallback(
|
_, err = meter.RegisterCallback(
|
||||||
func(ctx context.Context, obs metric.Observer) error {
|
func(_ context.Context, obs metric.Observer) error {
|
||||||
obs.ObserveInt64(intCnt, 1)
|
obs.ObserveInt64(intCnt, 1)
|
||||||
obs.ObserveInt64(intUDCnt, 1)
|
obs.ObserveInt64(intUDCnt, 1)
|
||||||
obs.ObserveInt64(intGaugeCnt, 1)
|
obs.ObserveInt64(intGaugeCnt, 1)
|
||||||
@@ -2566,7 +2566,7 @@ func TestMeterProviderDelegation(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
floatGauge, err := meter.Float64ObservableGauge("observable.float.gauge")
|
floatGauge, err := meter.Float64ObservableGauge("observable.float.gauge")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
_, err = meter.RegisterCallback(func(ctx context.Context, o metric.Observer) error {
|
_, err = meter.RegisterCallback(func(_ context.Context, o metric.Observer) error {
|
||||||
o.ObserveInt64(int64Counter, int64(10))
|
o.ObserveInt64(int64Counter, int64(10))
|
||||||
o.ObserveInt64(int64UpDownCounter, int64(10))
|
o.ObserveInt64(int64UpDownCounter, int64(10))
|
||||||
o.ObserveInt64(int64Gauge, int64(10))
|
o.ObserveInt64(int64Gauge, int64(10))
|
||||||
|
@@ -489,7 +489,7 @@ func TestPeriodicReaderCollect(t *testing.T) {
|
|||||||
// Ensure the pipeline has a callback setup
|
// Ensure the pipeline has a callback setup
|
||||||
testM, err := meter.Int64ObservableCounter("test")
|
testM, err := meter.Int64ObservableCounter("test")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
_, err = meter.RegisterCallback(func(_ context.Context, o metric.Observer) error {
|
_, err = meter.RegisterCallback(func(context.Context, metric.Observer) error {
|
||||||
return nil
|
return nil
|
||||||
}, testM)
|
}, testM)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
@@ -184,7 +184,7 @@ func testCreateAggregators[N int64 | float64](t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "Default/Drop",
|
name: "Default/Drop",
|
||||||
reader: NewManualReader(
|
reader: NewManualReader(
|
||||||
WithAggregationSelector(func(ik InstrumentKind) Aggregation { return AggregationDrop{} }),
|
WithAggregationSelector(func(InstrumentKind) Aggregation { return AggregationDrop{} }),
|
||||||
),
|
),
|
||||||
inst: instruments[InstrumentKindCounter],
|
inst: instruments[InstrumentKindCounter],
|
||||||
validate: func(t *testing.T, meas []aggregate.Measure[N], comps []aggregate.ComputeAggregation, err error) {
|
validate: func(t *testing.T, meas []aggregate.Measure[N], comps []aggregate.ComputeAggregation, err error) {
|
||||||
@@ -326,7 +326,7 @@ func testCreateAggregators[N int64 | float64](t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "Reader/Default/Cumulative/Sum/Monotonic",
|
name: "Reader/Default/Cumulative/Sum/Monotonic",
|
||||||
reader: NewManualReader(
|
reader: NewManualReader(
|
||||||
WithAggregationSelector(func(ik InstrumentKind) Aggregation { return AggregationDefault{} }),
|
WithAggregationSelector(func(InstrumentKind) Aggregation { return AggregationDefault{} }),
|
||||||
),
|
),
|
||||||
inst: instruments[InstrumentKindCounter],
|
inst: instruments[InstrumentKindCounter],
|
||||||
validate: assertSum[N](1, metricdata.CumulativeTemporality, true, [2]N{1, 4}),
|
validate: assertSum[N](1, metricdata.CumulativeTemporality, true, [2]N{1, 4}),
|
||||||
@@ -334,7 +334,7 @@ func testCreateAggregators[N int64 | float64](t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "Reader/Default/Cumulative/Sum/NonMonotonic",
|
name: "Reader/Default/Cumulative/Sum/NonMonotonic",
|
||||||
reader: NewManualReader(
|
reader: NewManualReader(
|
||||||
WithAggregationSelector(func(ik InstrumentKind) Aggregation { return AggregationDefault{} }),
|
WithAggregationSelector(func(InstrumentKind) Aggregation { return AggregationDefault{} }),
|
||||||
),
|
),
|
||||||
inst: instruments[InstrumentKindUpDownCounter],
|
inst: instruments[InstrumentKindUpDownCounter],
|
||||||
validate: assertSum[N](1, metricdata.CumulativeTemporality, false, [2]N{1, 4}),
|
validate: assertSum[N](1, metricdata.CumulativeTemporality, false, [2]N{1, 4}),
|
||||||
@@ -342,7 +342,7 @@ func testCreateAggregators[N int64 | float64](t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "Reader/Default/Cumulative/ExplicitBucketHistogram",
|
name: "Reader/Default/Cumulative/ExplicitBucketHistogram",
|
||||||
reader: NewManualReader(
|
reader: NewManualReader(
|
||||||
WithAggregationSelector(func(ik InstrumentKind) Aggregation { return AggregationDefault{} }),
|
WithAggregationSelector(func(InstrumentKind) Aggregation { return AggregationDefault{} }),
|
||||||
),
|
),
|
||||||
inst: instruments[InstrumentKindHistogram],
|
inst: instruments[InstrumentKindHistogram],
|
||||||
validate: assertHist[N](metricdata.CumulativeTemporality),
|
validate: assertHist[N](metricdata.CumulativeTemporality),
|
||||||
@@ -350,7 +350,7 @@ func testCreateAggregators[N int64 | float64](t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "Reader/Default/Cumulative/Gauge",
|
name: "Reader/Default/Cumulative/Gauge",
|
||||||
reader: NewManualReader(
|
reader: NewManualReader(
|
||||||
WithAggregationSelector(func(ik InstrumentKind) Aggregation { return AggregationDefault{} }),
|
WithAggregationSelector(func(InstrumentKind) Aggregation { return AggregationDefault{} }),
|
||||||
),
|
),
|
||||||
inst: instruments[InstrumentKindGauge],
|
inst: instruments[InstrumentKindGauge],
|
||||||
validate: assertLastValue[N],
|
validate: assertLastValue[N],
|
||||||
@@ -358,7 +358,7 @@ func testCreateAggregators[N int64 | float64](t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "Reader/Default/Cumulative/PrecomputedSum/Monotonic",
|
name: "Reader/Default/Cumulative/PrecomputedSum/Monotonic",
|
||||||
reader: NewManualReader(
|
reader: NewManualReader(
|
||||||
WithAggregationSelector(func(ik InstrumentKind) Aggregation { return AggregationDefault{} }),
|
WithAggregationSelector(func(InstrumentKind) Aggregation { return AggregationDefault{} }),
|
||||||
),
|
),
|
||||||
inst: instruments[InstrumentKindObservableCounter],
|
inst: instruments[InstrumentKindObservableCounter],
|
||||||
validate: assertSum[N](1, metricdata.CumulativeTemporality, true, [2]N{1, 3}),
|
validate: assertSum[N](1, metricdata.CumulativeTemporality, true, [2]N{1, 3}),
|
||||||
@@ -366,7 +366,7 @@ func testCreateAggregators[N int64 | float64](t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "Reader/Default/Cumulative/PrecomputedSum/NonMonotonic",
|
name: "Reader/Default/Cumulative/PrecomputedSum/NonMonotonic",
|
||||||
reader: NewManualReader(
|
reader: NewManualReader(
|
||||||
WithAggregationSelector(func(ik InstrumentKind) Aggregation { return AggregationDefault{} }),
|
WithAggregationSelector(func(InstrumentKind) Aggregation { return AggregationDefault{} }),
|
||||||
),
|
),
|
||||||
inst: instruments[InstrumentKindObservableUpDownCounter],
|
inst: instruments[InstrumentKindObservableUpDownCounter],
|
||||||
validate: assertSum[N](1, metricdata.CumulativeTemporality, false, [2]N{1, 3}),
|
validate: assertSum[N](1, metricdata.CumulativeTemporality, false, [2]N{1, 3}),
|
||||||
@@ -374,7 +374,7 @@ func testCreateAggregators[N int64 | float64](t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "Reader/Default/Gauge",
|
name: "Reader/Default/Gauge",
|
||||||
reader: NewManualReader(
|
reader: NewManualReader(
|
||||||
WithAggregationSelector(func(ik InstrumentKind) Aggregation { return AggregationDefault{} }),
|
WithAggregationSelector(func(InstrumentKind) Aggregation { return AggregationDefault{} }),
|
||||||
),
|
),
|
||||||
inst: instruments[InstrumentKindObservableGauge],
|
inst: instruments[InstrumentKindObservableGauge],
|
||||||
validate: assertLastValue[N],
|
validate: assertLastValue[N],
|
||||||
@@ -453,7 +453,7 @@ func TestPipelineRegistryCreateAggregators(t *testing.T) {
|
|||||||
renameView := NewView(Instrument{Name: "foo"}, Stream{Name: "bar"})
|
renameView := NewView(Instrument{Name: "foo"}, Stream{Name: "bar"})
|
||||||
testRdr := NewManualReader()
|
testRdr := NewManualReader()
|
||||||
testRdrHistogram := NewManualReader(
|
testRdrHistogram := NewManualReader(
|
||||||
WithAggregationSelector(func(ik InstrumentKind) Aggregation { return AggregationExplicitBucketHistogram{} }),
|
WithAggregationSelector(func(InstrumentKind) Aggregation { return AggregationExplicitBucketHistogram{} }),
|
||||||
)
|
)
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
@@ -566,7 +566,7 @@ func TestPipelineRegistryResource(t *testing.T) {
|
|||||||
|
|
||||||
func TestPipelineRegistryCreateAggregatorsIncompatibleInstrument(t *testing.T) {
|
func TestPipelineRegistryCreateAggregatorsIncompatibleInstrument(t *testing.T) {
|
||||||
testRdrHistogram := NewManualReader(
|
testRdrHistogram := NewManualReader(
|
||||||
WithAggregationSelector(func(ik InstrumentKind) Aggregation { return AggregationSum{} }),
|
WithAggregationSelector(func(InstrumentKind) Aggregation { return AggregationSum{} }),
|
||||||
)
|
)
|
||||||
|
|
||||||
readers := []Reader{testRdrHistogram}
|
readers := []Reader{testRdrHistogram}
|
||||||
|
@@ -76,7 +76,7 @@ func TestPipelineUsesResource(t *testing.T) {
|
|||||||
assert.Equal(t, res, output.Resource)
|
assert.Equal(t, res, output.Resource)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPipelineConcurrentSafe(t *testing.T) {
|
func TestPipelineConcurrentSafe(*testing.T) {
|
||||||
pipe := newPipeline(nil, nil, nil, exemplar.AlwaysOffFilter, 0)
|
pipe := newPipeline(nil, nil, nil, exemplar.AlwaysOffFilter, 0)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
var output metricdata.ResourceMetrics
|
var output metricdata.ResourceMetrics
|
||||||
@@ -511,7 +511,7 @@ func TestExemplars(t *testing.T) {
|
|||||||
|
|
||||||
t.Run("Custom reservoir", func(t *testing.T) {
|
t.Run("Custom reservoir", func(t *testing.T) {
|
||||||
r := NewManualReader()
|
r := NewManualReader()
|
||||||
reservoirProviderSelector := func(agg Aggregation) exemplar.ReservoirProvider {
|
reservoirProviderSelector := func(Aggregation) exemplar.ReservoirProvider {
|
||||||
return exemplar.FixedSizeReservoirProvider(2)
|
return exemplar.FixedSizeReservoirProvider(2)
|
||||||
}
|
}
|
||||||
v1 := NewView(Instrument{Name: "int64-expo-histogram"}, Stream{
|
v1 := NewView(Instrument{Name: "int64-expo-histogram"}, Stream{
|
||||||
@@ -663,7 +663,7 @@ func TestPipelineProduceErrors(t *testing.T) {
|
|||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
// Callback 2: populates int64 observable data
|
// Callback 2: populates int64 observable data
|
||||||
func(ctx context.Context) error {
|
func(context.Context) error {
|
||||||
callbackCounts[1]++
|
callbackCounts[1]++
|
||||||
if shouldCancelContext {
|
if shouldCancelContext {
|
||||||
cancelCtx()
|
cancelCtx()
|
||||||
@@ -671,7 +671,7 @@ func TestPipelineProduceErrors(t *testing.T) {
|
|||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
// Callback 3: return an error
|
// Callback 3: return an error
|
||||||
func(ctx context.Context) error {
|
func(context.Context) error {
|
||||||
callbackCounts[2]++
|
callbackCounts[2]++
|
||||||
if shouldReturnError {
|
if shouldReturnError {
|
||||||
return fmt.Errorf("test callback error")
|
return fmt.Errorf("test callback error")
|
||||||
|
@@ -21,7 +21,7 @@ import (
|
|||||||
"go.opentelemetry.io/otel/sdk/metric/metricdata"
|
"go.opentelemetry.io/otel/sdk/metric/metricdata"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMeterConcurrentSafe(t *testing.T) {
|
func TestMeterConcurrentSafe(*testing.T) {
|
||||||
const name = "TestMeterConcurrentSafe meter"
|
const name = "TestMeterConcurrentSafe meter"
|
||||||
mp := NewMeterProvider()
|
mp := NewMeterProvider()
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ func TestMeterConcurrentSafe(t *testing.T) {
|
|||||||
<-done
|
<-done
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestForceFlushConcurrentSafe(t *testing.T) {
|
func TestForceFlushConcurrentSafe(*testing.T) {
|
||||||
mp := NewMeterProvider()
|
mp := NewMeterProvider()
|
||||||
|
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
@@ -48,7 +48,7 @@ func TestForceFlushConcurrentSafe(t *testing.T) {
|
|||||||
<-done
|
<-done
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestShutdownConcurrentSafe(t *testing.T) {
|
func TestShutdownConcurrentSafe(*testing.T) {
|
||||||
mp := NewMeterProvider()
|
mp := NewMeterProvider()
|
||||||
|
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
@@ -61,7 +61,7 @@ func TestShutdownConcurrentSafe(t *testing.T) {
|
|||||||
<-done
|
<-done
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMeterAndShutdownConcurrentSafe(t *testing.T) {
|
func TestMeterAndShutdownConcurrentSafe(*testing.T) {
|
||||||
const name = "TestMeterAndShutdownConcurrentSafe meter"
|
const name = "TestMeterAndShutdownConcurrentSafe meter"
|
||||||
mp := NewMeterProvider()
|
mp := NewMeterProvider()
|
||||||
|
|
||||||
|
@@ -83,7 +83,7 @@ func (ts *readerTestSuite) TestShutdownTwice() {
|
|||||||
func (ts *readerTestSuite) TestMultipleRegister() {
|
func (ts *readerTestSuite) TestMultipleRegister() {
|
||||||
ts.Reader = ts.Factory()
|
ts.Reader = ts.Factory()
|
||||||
p0 := testSDKProducer{
|
p0 := testSDKProducer{
|
||||||
produceFunc: func(ctx context.Context, rm *metricdata.ResourceMetrics) error {
|
produceFunc: func(_ context.Context, rm *metricdata.ResourceMetrics) error {
|
||||||
// Differentiate this producer from the second by returning an
|
// Differentiate this producer from the second by returning an
|
||||||
// error.
|
// error.
|
||||||
*rm = testResourceMetricsA
|
*rm = testResourceMetricsA
|
||||||
@@ -103,12 +103,12 @@ func (ts *readerTestSuite) TestMultipleRegister() {
|
|||||||
func (ts *readerTestSuite) TestExternalProducerPartialSuccess() {
|
func (ts *readerTestSuite) TestExternalProducerPartialSuccess() {
|
||||||
ts.Reader = ts.Factory(
|
ts.Reader = ts.Factory(
|
||||||
WithProducer(testExternalProducer{
|
WithProducer(testExternalProducer{
|
||||||
produceFunc: func(ctx context.Context) ([]metricdata.ScopeMetrics, error) {
|
produceFunc: func(context.Context) ([]metricdata.ScopeMetrics, error) {
|
||||||
return []metricdata.ScopeMetrics{}, assert.AnError
|
return []metricdata.ScopeMetrics{}, assert.AnError
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
WithProducer(testExternalProducer{
|
WithProducer(testExternalProducer{
|
||||||
produceFunc: func(ctx context.Context) ([]metricdata.ScopeMetrics, error) {
|
produceFunc: func(context.Context) ([]metricdata.ScopeMetrics, error) {
|
||||||
return []metricdata.ScopeMetrics{testScopeMetricsB}, nil
|
return []metricdata.ScopeMetrics{testScopeMetricsB}, nil
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
@@ -124,7 +124,7 @@ func (ts *readerTestSuite) TestExternalProducerPartialSuccess() {
|
|||||||
func (ts *readerTestSuite) TestSDKFailureBlocksExternalProducer() {
|
func (ts *readerTestSuite) TestSDKFailureBlocksExternalProducer() {
|
||||||
ts.Reader = ts.Factory(WithProducer(testExternalProducer{}))
|
ts.Reader = ts.Factory(WithProducer(testExternalProducer{}))
|
||||||
ts.Reader.register(testSDKProducer{
|
ts.Reader.register(testSDKProducer{
|
||||||
produceFunc: func(ctx context.Context, rm *metricdata.ResourceMetrics) error {
|
produceFunc: func(_ context.Context, rm *metricdata.ResourceMetrics) error {
|
||||||
*rm = metricdata.ResourceMetrics{}
|
*rm = metricdata.ResourceMetrics{}
|
||||||
return assert.AnError
|
return assert.AnError
|
||||||
},
|
},
|
||||||
|
@@ -400,7 +400,7 @@ func TestNewViewReplace(t *testing.T) {
|
|||||||
Unit: "1",
|
Unit: "1",
|
||||||
Aggregation: AggregationLastValue{},
|
Aggregation: AggregationLastValue{},
|
||||||
},
|
},
|
||||||
want: func(i Instrument) Stream {
|
want: func(Instrument) Stream {
|
||||||
return Stream{
|
return Stream{
|
||||||
Name: alt,
|
Name: alt,
|
||||||
Description: alt,
|
Description: alt,
|
||||||
|
@@ -72,7 +72,7 @@ func StringDetector(schemaURL string, k attribute.Key, f func() (string, error))
|
|||||||
|
|
||||||
// Detect returns a *Resource that describes the string as a value
|
// Detect returns a *Resource that describes the string as a value
|
||||||
// corresponding to attribute.Key as well as the specific schemaURL.
|
// corresponding to attribute.Key as well as the specific schemaURL.
|
||||||
func (sd stringDetector) Detect(ctx context.Context) (*Resource, error) {
|
func (sd stringDetector) Detect(context.Context) (*Resource, error) {
|
||||||
value, err := sd.F()
|
value, err := sd.F()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("%s: %w", string(sd.K), err)
|
return nil, fmt.Errorf("%s: %w", string(sd.K), err)
|
||||||
|
@@ -27,7 +27,7 @@ const cgroupPath = "/proc/self/cgroup"
|
|||||||
|
|
||||||
// Detect returns a *Resource that describes the id of the container.
|
// Detect returns a *Resource that describes the id of the container.
|
||||||
// If no container id found, an empty resource will be returned.
|
// If no container id found, an empty resource will be returned.
|
||||||
func (cgroupContainerIDDetector) Detect(ctx context.Context) (*Resource, error) {
|
func (cgroupContainerIDDetector) Detect(context.Context) (*Resource, error) {
|
||||||
containerID, err := containerID()
|
containerID, err := containerID()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@@ -141,14 +141,14 @@ func TestGetContainerIDFromCGroup(t *testing.T) {
|
|||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
osStat = func(name string) (os.FileInfo, error) {
|
osStat = func(string) (os.FileInfo, error) {
|
||||||
if tc.cgroupFileNotExist {
|
if tc.cgroupFileNotExist {
|
||||||
return nil, os.ErrNotExist
|
return nil, os.ErrNotExist
|
||||||
}
|
}
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
osOpen = func(name string) (io.ReadCloser, error) {
|
osOpen = func(string) (io.ReadCloser, error) {
|
||||||
if tc.openFileError != nil {
|
if tc.openFileError != nil {
|
||||||
return nil, tc.openFileError
|
return nil, tc.openFileError
|
||||||
}
|
}
|
||||||
|
@@ -96,7 +96,7 @@ func (r *hostIDReaderLinux) read() (string, error) {
|
|||||||
type hostIDDetector struct{}
|
type hostIDDetector struct{}
|
||||||
|
|
||||||
// Detect returns a *Resource containing the platform specific host id.
|
// Detect returns a *Resource containing the platform specific host id.
|
||||||
func (hostIDDetector) Detect(ctx context.Context) (*Resource, error) {
|
func (hostIDDetector) Detect(context.Context) (*Resource, error) {
|
||||||
hostID, err := hostID()
|
hostID, err := hostID()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@@ -13,11 +13,11 @@ import (
|
|||||||
var (
|
var (
|
||||||
expectedHostID = "f2c668b579780554f70f72a063dc0864"
|
expectedHostID = "f2c668b579780554f70f72a063dc0864"
|
||||||
|
|
||||||
readFileNoError = func(filename string) (string, error) {
|
readFileNoError = func(string) (string, error) {
|
||||||
return expectedHostID + "\n", nil
|
return expectedHostID + "\n", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
readFileError = func(filename string) (string, error) {
|
readFileError = func(string) (string, error) {
|
||||||
return "", errors.New("not found")
|
return "", errors.New("not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -32,7 +32,7 @@ type (
|
|||||||
|
|
||||||
// Detect returns a *Resource that describes the operating system type the
|
// Detect returns a *Resource that describes the operating system type the
|
||||||
// service is running on.
|
// service is running on.
|
||||||
func (osTypeDetector) Detect(ctx context.Context) (*Resource, error) {
|
func (osTypeDetector) Detect(context.Context) (*Resource, error) {
|
||||||
osType := runtimeOS()
|
osType := runtimeOS()
|
||||||
|
|
||||||
osTypeAttribute := mapRuntimeOSToSemconvOSType(osType)
|
osTypeAttribute := mapRuntimeOSToSemconvOSType(osType)
|
||||||
@@ -45,7 +45,7 @@ func (osTypeDetector) Detect(ctx context.Context) (*Resource, error) {
|
|||||||
|
|
||||||
// Detect returns a *Resource that describes the operating system the
|
// Detect returns a *Resource that describes the operating system the
|
||||||
// service is running on.
|
// service is running on.
|
||||||
func (osDescriptionDetector) Detect(ctx context.Context) (*Resource, error) {
|
func (osDescriptionDetector) Detect(context.Context) (*Resource, error) {
|
||||||
description, err := osDescription()
|
description, err := osDescription()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@@ -27,7 +27,7 @@ func fakeUnameProvider(buf *unix.Utsname) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func fakeUnameProviderWithError(buf *unix.Utsname) error {
|
func fakeUnameProviderWithError(*unix.Utsname) error {
|
||||||
return fmt.Errorf("error invoking uname(2)")
|
return fmt.Errorf("error invoking uname(2)")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -112,19 +112,19 @@ type (
|
|||||||
|
|
||||||
// Detect returns a *Resource that describes the process identifier (PID) of the
|
// Detect returns a *Resource that describes the process identifier (PID) of the
|
||||||
// executing process.
|
// executing process.
|
||||||
func (processPIDDetector) Detect(ctx context.Context) (*Resource, error) {
|
func (processPIDDetector) Detect(context.Context) (*Resource, error) {
|
||||||
return NewWithAttributes(semconv.SchemaURL, semconv.ProcessPID(pid())), nil
|
return NewWithAttributes(semconv.SchemaURL, semconv.ProcessPID(pid())), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Detect returns a *Resource that describes the name of the process executable.
|
// Detect returns a *Resource that describes the name of the process executable.
|
||||||
func (processExecutableNameDetector) Detect(ctx context.Context) (*Resource, error) {
|
func (processExecutableNameDetector) Detect(context.Context) (*Resource, error) {
|
||||||
executableName := filepath.Base(commandArgs()[0])
|
executableName := filepath.Base(commandArgs()[0])
|
||||||
|
|
||||||
return NewWithAttributes(semconv.SchemaURL, semconv.ProcessExecutableName(executableName)), nil
|
return NewWithAttributes(semconv.SchemaURL, semconv.ProcessExecutableName(executableName)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Detect returns a *Resource that describes the full path of the process executable.
|
// Detect returns a *Resource that describes the full path of the process executable.
|
||||||
func (processExecutablePathDetector) Detect(ctx context.Context) (*Resource, error) {
|
func (processExecutablePathDetector) Detect(context.Context) (*Resource, error) {
|
||||||
executablePath, err := executablePath()
|
executablePath, err := executablePath()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -135,13 +135,13 @@ func (processExecutablePathDetector) Detect(ctx context.Context) (*Resource, err
|
|||||||
|
|
||||||
// Detect returns a *Resource that describes all the command arguments as received
|
// Detect returns a *Resource that describes all the command arguments as received
|
||||||
// by the process.
|
// by the process.
|
||||||
func (processCommandArgsDetector) Detect(ctx context.Context) (*Resource, error) {
|
func (processCommandArgsDetector) Detect(context.Context) (*Resource, error) {
|
||||||
return NewWithAttributes(semconv.SchemaURL, semconv.ProcessCommandArgs(commandArgs()...)), nil
|
return NewWithAttributes(semconv.SchemaURL, semconv.ProcessCommandArgs(commandArgs()...)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Detect returns a *Resource that describes the username of the user that owns the
|
// Detect returns a *Resource that describes the username of the user that owns the
|
||||||
// process.
|
// process.
|
||||||
func (processOwnerDetector) Detect(ctx context.Context) (*Resource, error) {
|
func (processOwnerDetector) Detect(context.Context) (*Resource, error) {
|
||||||
owner, err := owner()
|
owner, err := owner()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -152,17 +152,17 @@ func (processOwnerDetector) Detect(ctx context.Context) (*Resource, error) {
|
|||||||
|
|
||||||
// Detect returns a *Resource that describes the name of the compiler used to compile
|
// Detect returns a *Resource that describes the name of the compiler used to compile
|
||||||
// this process image.
|
// this process image.
|
||||||
func (processRuntimeNameDetector) Detect(ctx context.Context) (*Resource, error) {
|
func (processRuntimeNameDetector) Detect(context.Context) (*Resource, error) {
|
||||||
return NewWithAttributes(semconv.SchemaURL, semconv.ProcessRuntimeName(runtimeName())), nil
|
return NewWithAttributes(semconv.SchemaURL, semconv.ProcessRuntimeName(runtimeName())), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Detect returns a *Resource that describes the version of the runtime of this process.
|
// Detect returns a *Resource that describes the version of the runtime of this process.
|
||||||
func (processRuntimeVersionDetector) Detect(ctx context.Context) (*Resource, error) {
|
func (processRuntimeVersionDetector) Detect(context.Context) (*Resource, error) {
|
||||||
return NewWithAttributes(semconv.SchemaURL, semconv.ProcessRuntimeVersion(runtimeVersion())), nil
|
return NewWithAttributes(semconv.SchemaURL, semconv.ProcessRuntimeVersion(runtimeVersion())), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Detect returns a *Resource that describes the runtime of this process.
|
// Detect returns a *Resource that describes the runtime of this process.
|
||||||
func (processRuntimeDescriptionDetector) Detect(ctx context.Context) (*Resource, error) {
|
func (processRuntimeDescriptionDetector) Detect(context.Context) (*Resource, error) {
|
||||||
runtimeDescription := fmt.Sprintf(
|
runtimeDescription := fmt.Sprintf(
|
||||||
"go version %s %s/%s", runtimeVersion(), runtimeOS(), runtimeArch())
|
"go version %s %s/%s", runtimeVersion(), runtimeOS(), runtimeArch())
|
||||||
|
|
||||||
|
@@ -796,7 +796,7 @@ func TestResourceConcurrentSafe(t *testing.T) {
|
|||||||
|
|
||||||
type fakeDetector struct{}
|
type fakeDetector struct{}
|
||||||
|
|
||||||
func (f fakeDetector) Detect(_ context.Context) (*resource.Resource, error) {
|
func (f fakeDetector) Detect(context.Context) (*resource.Resource, error) {
|
||||||
// A bit pedantic, but resource.NewWithAttributes returns an empty Resource when
|
// A bit pedantic, but resource.NewWithAttributes returns an empty Resource when
|
||||||
// no attributes specified. We want to make sure that this is concurrent-safe.
|
// no attributes specified. We want to make sure that this is concurrent-safe.
|
||||||
return resource.NewWithAttributes("https://opentelemetry.io/schemas/1.21.0"), nil
|
return resource.NewWithAttributes("https://opentelemetry.io/schemas/1.21.0"), nil
|
||||||
|
@@ -121,7 +121,7 @@ func NewBatchSpanProcessor(exporter SpanExporter, options ...BatchSpanProcessorO
|
|||||||
}
|
}
|
||||||
|
|
||||||
// OnStart method does nothing.
|
// OnStart method does nothing.
|
||||||
func (bsp *batchSpanProcessor) OnStart(parent context.Context, s ReadWriteSpan) {}
|
func (bsp *batchSpanProcessor) OnStart(context.Context, ReadWriteSpan) {}
|
||||||
|
|
||||||
// OnEnd method enqueues a ReadOnlySpan for later processing.
|
// OnEnd method enqueues a ReadOnlySpan for later processing.
|
||||||
func (bsp *batchSpanProcessor) OnEnd(s ReadOnlySpan) {
|
func (bsp *batchSpanProcessor) OnEnd(s ReadOnlySpan) {
|
||||||
|
@@ -367,7 +367,7 @@ func BenchmarkSpanProcessorVerboseLogging(b *testing.B) {
|
|||||||
b.Cleanup(func(l logr.Logger) func() {
|
b.Cleanup(func(l logr.Logger) func() {
|
||||||
return func() { global.SetLogger(l) }
|
return func() { global.SetLogger(l) }
|
||||||
}(global.GetLogger()))
|
}(global.GetLogger()))
|
||||||
global.SetLogger(funcr.New(func(prefix, args string) {}, funcr.Options{Verbosity: 5}))
|
global.SetLogger(funcr.New(func(string, string) {}, funcr.Options{Verbosity: 5}))
|
||||||
tp := sdktrace.NewTracerProvider(
|
tp := sdktrace.NewTracerProvider(
|
||||||
sdktrace.WithBatcher(
|
sdktrace.WithBatcher(
|
||||||
tracetest.NewNoopExporter(),
|
tracetest.NewNoopExporter(),
|
||||||
|
@@ -45,7 +45,7 @@ func TestDropCount(t *testing.T) {
|
|||||||
t.Cleanup(func(l logr.Logger) func() {
|
t.Cleanup(func(l logr.Logger) func() {
|
||||||
return func() { global.SetLogger(l) }
|
return func() { global.SetLogger(l) }
|
||||||
}(global.GetLogger()))
|
}(global.GetLogger()))
|
||||||
global.SetLogger(funcr.New(func(prefix, args string) {
|
global.SetLogger(funcr.New(func(string, string) {
|
||||||
called++
|
called++
|
||||||
}, funcr.Options{Verbosity: 1}))
|
}, funcr.Options{Verbosity: 1}))
|
||||||
|
|
||||||
|
@@ -32,7 +32,7 @@ type randomIDGenerator struct{}
|
|||||||
var _ IDGenerator = &randomIDGenerator{}
|
var _ IDGenerator = &randomIDGenerator{}
|
||||||
|
|
||||||
// NewSpanID returns a non-zero span ID from a randomly-chosen sequence.
|
// NewSpanID returns a non-zero span ID from a randomly-chosen sequence.
|
||||||
func (gen *randomIDGenerator) NewSpanID(ctx context.Context, traceID trace.TraceID) trace.SpanID {
|
func (gen *randomIDGenerator) NewSpanID(context.Context, trace.TraceID) trace.SpanID {
|
||||||
sid := trace.SpanID{}
|
sid := trace.SpanID{}
|
||||||
for {
|
for {
|
||||||
binary.NativeEndian.PutUint64(sid[:], rand.Uint64())
|
binary.NativeEndian.PutUint64(sid[:], rand.Uint64())
|
||||||
@@ -45,7 +45,7 @@ func (gen *randomIDGenerator) NewSpanID(ctx context.Context, traceID trace.Trace
|
|||||||
|
|
||||||
// NewIDs returns a non-zero trace ID and a non-zero span ID from a
|
// NewIDs returns a non-zero trace ID and a non-zero span ID from a
|
||||||
// randomly-chosen sequence.
|
// randomly-chosen sequence.
|
||||||
func (gen *randomIDGenerator) NewIDs(ctx context.Context) (trace.TraceID, trace.SpanID) {
|
func (gen *randomIDGenerator) NewIDs(context.Context) (trace.TraceID, trace.SpanID) {
|
||||||
tid := trace.TraceID{}
|
tid := trace.TraceID{}
|
||||||
sid := trace.SpanID{}
|
sid := trace.SpanID{}
|
||||||
for {
|
for {
|
||||||
|
@@ -57,7 +57,7 @@ func (t *shutdownSpanProcessor) ForceFlush(context.Context) error {
|
|||||||
func TestShutdownCallsTracerMethod(t *testing.T) {
|
func TestShutdownCallsTracerMethod(t *testing.T) {
|
||||||
stp := NewTracerProvider()
|
stp := NewTracerProvider()
|
||||||
sp := &shutdownSpanProcessor{
|
sp := &shutdownSpanProcessor{
|
||||||
shutdown: func(ctx context.Context) error {
|
shutdown: func(context.Context) error {
|
||||||
_ = stp.Tracer("abc") // must not deadlock
|
_ = stp.Tracer("abc") // must not deadlock
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
@@ -18,7 +18,7 @@ type simpleTestExporter struct {
|
|||||||
shutdown bool
|
shutdown bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *simpleTestExporter) ExportSpans(ctx context.Context, spans []ReadOnlySpan) error {
|
func (t *simpleTestExporter) ExportSpans(_ context.Context, spans []ReadOnlySpan) error {
|
||||||
t.spans = append(t.spans, spans...)
|
t.spans = append(t.spans, spans...)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@@ -52,7 +52,7 @@ func (t *testSpanProcessor) OnEnd(s ReadOnlySpan) {
|
|||||||
t.spansEnded = append(t.spansEnded, s)
|
t.spansEnded = append(t.spansEnded, s)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *testSpanProcessor) Shutdown(_ context.Context) error {
|
func (t *testSpanProcessor) Shutdown(context.Context) error {
|
||||||
if t == nil {
|
if t == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@@ -1148,7 +1148,7 @@ func TestChildSpanCount(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNilSpanEnd(t *testing.T) {
|
func TestNilSpanEnd(*testing.T) {
|
||||||
var span *recordingSpan
|
var span *recordingSpan
|
||||||
span.End()
|
span.End()
|
||||||
}
|
}
|
||||||
@@ -1824,7 +1824,7 @@ func TestSamplerTraceState(t *testing.T) {
|
|||||||
clearer := func(prefix string) Sampler {
|
clearer := func(prefix string) Sampler {
|
||||||
return &stateSampler{
|
return &stateSampler{
|
||||||
prefix: prefix,
|
prefix: prefix,
|
||||||
f: func(t trace.TraceState) trace.TraceState { return trace.TraceState{} },
|
f: func(trace.TraceState) trace.TraceState { return trace.TraceState{} },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1943,7 +1943,7 @@ func (gen *testIDGenerator) NewIDs(ctx context.Context) (trace.TraceID, trace.Sp
|
|||||||
return traceID, spanID
|
return traceID, spanID
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gen *testIDGenerator) NewSpanID(ctx context.Context, traceID trace.TraceID) trace.SpanID {
|
func (gen *testIDGenerator) NewSpanID(context.Context, trace.TraceID) trace.SpanID {
|
||||||
spanIDHex := fmt.Sprintf("%016x", gen.spanID)
|
spanIDHex := fmt.Sprintf("%016x", gen.spanID)
|
||||||
spanID, _ := trace.SpanIDFromHex(spanIDHex)
|
spanID, _ := trace.SpanIDFromHex(spanIDHex)
|
||||||
gen.spanID++
|
gen.spanID++
|
||||||
|
@@ -37,7 +37,7 @@ var _ Tracer = noopTracer{}
|
|||||||
|
|
||||||
// Start carries forward a non-recording Span, if one is present in the context, otherwise it
|
// Start carries forward a non-recording Span, if one is present in the context, otherwise it
|
||||||
// creates a no-op Span.
|
// creates a no-op Span.
|
||||||
func (t noopTracer) Start(ctx context.Context, name string, _ ...SpanStartOption) (context.Context, Span) {
|
func (t noopTracer) Start(ctx context.Context, _ string, _ ...SpanStartOption) (context.Context, Span) {
|
||||||
span := SpanFromContext(ctx)
|
span := SpanFromContext(ctx)
|
||||||
if _, ok := span.(nonRecordingSpan); !ok {
|
if _, ok := span.(nonRecordingSpan); !ok {
|
||||||
// span is likely already a noopSpan, but let's be sure
|
// span is likely already a noopSpan, but let's be sure
|
||||||
|
@@ -17,7 +17,7 @@ type testTracerProvider struct{ embedded.TracerProvider }
|
|||||||
|
|
||||||
var _ trace.TracerProvider = &testTracerProvider{}
|
var _ trace.TracerProvider = &testTracerProvider{}
|
||||||
|
|
||||||
func (*testTracerProvider) Tracer(_ string, _ ...trace.TracerOption) trace.Tracer {
|
func (*testTracerProvider) Tracer(string, ...trace.TracerOption) trace.Tracer {
|
||||||
return noop.NewTracerProvider().Tracer("")
|
return noop.NewTracerProvider().Tracer("")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user