Skip to content

Commit 50a47b9

Browse files
Merge branch 'main' into ExampleSetTextMapPropagator
2 parents fdea4c6 + 7512a2b commit 50a47b9

File tree

96 files changed

+1774
-426
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+1774
-426
lines changed

.golangci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,13 @@ formatters:
235235
enable:
236236
- gofumpt
237237
- goimports
238+
- golines
238239
settings:
239240
goimports:
240241
local-prefixes:
241242
- go.opentelemetry.io
243+
golines:
244+
max-len: 120
242245
exclusions:
243246
generated: lax
244247
paths:

attribute/set_test.go

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,47 @@ func TestSetDedup(t *testing.T) {
4343
cases := []testCase{
4444
expect("A=B", attribute.String("A", "2"), attribute.String("A", "B")),
4545
expect("A=B", attribute.String("A", "2"), attribute.Int("A", 1), attribute.String("A", "B")),
46-
expect("A=B", attribute.String("A", "B"), attribute.String("A", "C"), attribute.String("A", "D"), attribute.String("A", "B")),
46+
expect(
47+
"A=B",
48+
attribute.String("A", "B"),
49+
attribute.String("A", "C"),
50+
attribute.String("A", "D"),
51+
attribute.String("A", "B"),
52+
),
4753

4854
expect("A=B,C=D", attribute.String("A", "1"), attribute.String("C", "D"), attribute.String("A", "B")),
4955
expect("A=B,C=D", attribute.String("A", "2"), attribute.String("A", "B"), attribute.String("C", "D")),
50-
expect("A=B,C=D", attribute.Float64("C", 1.2), attribute.String("A", "2"), attribute.String("A", "B"), attribute.String("C", "D")),
51-
expect("A=B,C=D", attribute.String("C", "D"), attribute.String("A", "B"), attribute.String("A", "C"), attribute.String("A", "D"), attribute.String("A", "B")),
52-
expect("A=B,C=D", attribute.String("A", "B"), attribute.String("C", "D"), attribute.String("A", "C"), attribute.String("A", "D"), attribute.String("A", "B")),
53-
expect("A=B,C=D", attribute.String("A", "B"), attribute.String("A", "C"), attribute.String("A", "D"), attribute.String("A", "B"), attribute.String("C", "D")),
56+
expect(
57+
"A=B,C=D",
58+
attribute.Float64("C", 1.2),
59+
attribute.String("A", "2"),
60+
attribute.String("A", "B"),
61+
attribute.String("C", "D"),
62+
),
63+
expect(
64+
"A=B,C=D",
65+
attribute.String("C", "D"),
66+
attribute.String("A", "B"),
67+
attribute.String("A", "C"),
68+
attribute.String("A", "D"),
69+
attribute.String("A", "B"),
70+
),
71+
expect(
72+
"A=B,C=D",
73+
attribute.String("A", "B"),
74+
attribute.String("C", "D"),
75+
attribute.String("A", "C"),
76+
attribute.String("A", "D"),
77+
attribute.String("A", "B"),
78+
),
79+
expect(
80+
"A=B,C=D",
81+
attribute.String("A", "B"),
82+
attribute.String("A", "C"),
83+
attribute.String("A", "D"),
84+
attribute.String("A", "B"),
85+
attribute.String("C", "D"),
86+
),
5487
}
5588
enc := attribute.DefaultEncoder()
5689

baggage/baggage_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1173,7 +1173,9 @@ func BenchmarkParse(b *testing.B) {
11731173
b.ReportAllocs()
11741174

11751175
for i := 0; i < b.N; i++ {
1176-
benchBaggage, _ = Parse("userId=alice,serverNode = DF28 , isProduction = false,hasProp=stuff;propKey;propWValue=value, invalidUtf8=pr%ffo%ffp%fcValue")
1176+
benchBaggage, _ = Parse(
1177+
"userId=alice,serverNode = DF28 , isProduction = false,hasProp=stuff;propKey;propWValue=value, invalidUtf8=pr%ffo%ffp%fcValue",
1178+
)
11771179
}
11781180
}
11791181

bridge/opencensus/internal/oc2otel/attributes_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ func TestAttributesFromMap(t *testing.T) {
5656
gotAttributeSet := attribute.NewSet(got...)
5757
wantAttributeSet := attribute.NewSet(want...)
5858
if !gotAttributeSet.Equals(&wantAttributeSet) {
59-
t.Errorf("Attributes conversion want %v, got %v", wantAttributeSet.Encoded(attribute.DefaultEncoder()), gotAttributeSet.Encoded(attribute.DefaultEncoder()))
59+
t.Errorf(
60+
"Attributes conversion want %v, got %v",
61+
wantAttributeSet.Encoded(attribute.DefaultEncoder()),
62+
gotAttributeSet.Encoded(attribute.DefaultEncoder()),
63+
)
6064
}
6165
}
6266

bridge/opencensus/internal/ocmetric/metric.go

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ var (
2626
errNegativeCount = errors.New("distribution or summary count is negative")
2727
errNegativeBucketCount = errors.New("distribution bucket count is negative")
2828
errMismatchedAttributeKeyValues = errors.New("mismatched number of attribute keys and values")
29-
errInvalidExemplarSpanContext = errors.New("span context exemplar attachment does not contain an OpenCensus SpanContext")
29+
errInvalidExemplarSpanContext = errors.New(
30+
"span context exemplar attachment does not contain an OpenCensus SpanContext",
31+
)
3032
)
3133

3234
// ConvertMetrics converts metric data from OpenCensus to OpenTelemetry.
@@ -76,20 +78,29 @@ func convertAggregation(metric *ocmetricdata.Metric) (metricdata.Aggregation, er
7678
}
7779

7880
// convertGauge converts an OpenCensus gauge to an OpenTelemetry gauge aggregation.
79-
func convertGauge[N int64 | float64](labelKeys []ocmetricdata.LabelKey, ts []*ocmetricdata.TimeSeries) (metricdata.Gauge[N], error) {
81+
func convertGauge[N int64 | float64](
82+
labelKeys []ocmetricdata.LabelKey,
83+
ts []*ocmetricdata.TimeSeries,
84+
) (metricdata.Gauge[N], error) {
8085
points, err := convertNumberDataPoints[N](labelKeys, ts)
8186
return metricdata.Gauge[N]{DataPoints: points}, err
8287
}
8388

8489
// convertSum converts an OpenCensus cumulative to an OpenTelemetry sum aggregation.
85-
func convertSum[N int64 | float64](labelKeys []ocmetricdata.LabelKey, ts []*ocmetricdata.TimeSeries) (metricdata.Sum[N], error) {
90+
func convertSum[N int64 | float64](
91+
labelKeys []ocmetricdata.LabelKey,
92+
ts []*ocmetricdata.TimeSeries,
93+
) (metricdata.Sum[N], error) {
8694
points, err := convertNumberDataPoints[N](labelKeys, ts)
8795
// OpenCensus sums are always Cumulative
8896
return metricdata.Sum[N]{DataPoints: points, Temporality: metricdata.CumulativeTemporality, IsMonotonic: true}, err
8997
}
9098

9199
// convertNumberDataPoints converts OpenCensus TimeSeries to OpenTelemetry DataPoints.
92-
func convertNumberDataPoints[N int64 | float64](labelKeys []ocmetricdata.LabelKey, ts []*ocmetricdata.TimeSeries) ([]metricdata.DataPoint[N], error) {
100+
func convertNumberDataPoints[N int64 | float64](
101+
labelKeys []ocmetricdata.LabelKey,
102+
ts []*ocmetricdata.TimeSeries,
103+
) ([]metricdata.DataPoint[N], error) {
93104
var points []metricdata.DataPoint[N]
94105
var err error
95106
for _, t := range ts {
@@ -117,7 +128,10 @@ func convertNumberDataPoints[N int64 | float64](labelKeys []ocmetricdata.LabelKe
117128

118129
// convertHistogram converts OpenCensus Distribution timeseries to an
119130
// OpenTelemetry Histogram aggregation.
120-
func convertHistogram(labelKeys []ocmetricdata.LabelKey, ts []*ocmetricdata.TimeSeries) (metricdata.Histogram[float64], error) {
131+
func convertHistogram(
132+
labelKeys []ocmetricdata.LabelKey,
133+
ts []*ocmetricdata.TimeSeries,
134+
) (metricdata.Histogram[float64], error) {
121135
points := make([]metricdata.HistogramDataPoint[float64], 0, len(ts))
122136
var err error
123137
for _, t := range ts {
@@ -390,7 +404,12 @@ func convertQuantiles(snapshot ocmetricdata.Snapshot) []metricdata.QuantileValue
390404
// OpenTelemetry attribute Set.
391405
func convertAttrs(keys []ocmetricdata.LabelKey, values []ocmetricdata.LabelValue) (attribute.Set, error) {
392406
if len(keys) != len(values) {
393-
return attribute.NewSet(), fmt.Errorf("%w: keys(%q) values(%q)", errMismatchedAttributeKeyValues, len(keys), len(values))
407+
return attribute.NewSet(), fmt.Errorf(
408+
"%w: keys(%q) values(%q)",
409+
errMismatchedAttributeKeyValues,
410+
len(keys),
411+
len(values),
412+
)
394413
}
395414
attrs := []attribute.KeyValue{}
396415
for i, lv := range values {

bridge/opencensus/internal/ocmetric/metric_test.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -989,10 +989,22 @@ func TestConvertAttributes(t *testing.T) {
989989
t.Run(tc.desc, func(t *testing.T) {
990990
output, err := convertAttrs(tc.inputKeys, tc.inputValues)
991991
if !errors.Is(err, tc.expectedErr) {
992-
t.Errorf("convertAttrs(keys: %v, values: %v) = err(%v), want err(%v)", tc.inputKeys, tc.inputValues, err, tc.expectedErr)
992+
t.Errorf(
993+
"convertAttrs(keys: %v, values: %v) = err(%v), want err(%v)",
994+
tc.inputKeys,
995+
tc.inputValues,
996+
err,
997+
tc.expectedErr,
998+
)
993999
}
9941000
if !output.Equals(tc.expected) {
995-
t.Errorf("convertAttrs(keys: %v, values: %v) = %+v, want %+v", tc.inputKeys, tc.inputValues, output.ToSlice(), tc.expected.ToSlice())
1001+
t.Errorf(
1002+
"convertAttrs(keys: %v, values: %v) = %+v, want %+v",
1003+
tc.inputKeys,
1004+
tc.inputValues,
1005+
output.ToSlice(),
1006+
tc.expected.ToSlice(),
1007+
)
9961008
}
9971009
})
9981010
}

bridge/opencensus/internal/span_test.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,18 @@ func TestSpanSetStatus(t *testing.T) {
124124
ocS.SetStatus(status)
125125

126126
if s.sCode != tt.wantCode {
127-
t.Errorf("span.SetStatus failed to set OpenTelemetry status code. Expected %d, got %d", tt.wantCode, s.sCode)
127+
t.Errorf(
128+
"span.SetStatus failed to set OpenTelemetry status code. Expected %d, got %d",
129+
tt.wantCode,
130+
s.sCode,
131+
)
128132
}
129133
if s.sMsg != tt.message {
130-
t.Errorf("span.SetStatus failed to set OpenTelemetry status description. Expected %s, got %s", tt.message, s.sMsg)
134+
t.Errorf(
135+
"span.SetStatus failed to set OpenTelemetry status description. Expected %s, got %s",
136+
tt.message,
137+
s.sMsg,
138+
)
131139
}
132140
})
133141
}
@@ -295,12 +303,22 @@ func TestSpanAddLinkFails(t *testing.T) {
295303

296304
for i, l := range s.links {
297305
if !l.SpanContext.Equal(wantLinks[i].SpanContext) {
298-
t.Errorf("link[%v] has the wrong span context; want %+v, got %+v", i, wantLinks[i].SpanContext, l.SpanContext)
306+
t.Errorf(
307+
"link[%v] has the wrong span context; want %+v, got %+v",
308+
i,
309+
wantLinks[i].SpanContext,
310+
l.SpanContext,
311+
)
299312
}
300313
gotAttributeSet := attribute.NewSet(l.Attributes...)
301314
wantAttributeSet := attribute.NewSet(wantLinks[i].Attributes...)
302315
if !gotAttributeSet.Equals(&wantAttributeSet) {
303-
t.Errorf("link[%v] has the wrong attributes; want %v, got %v", i, wantAttributeSet.Encoded(attribute.DefaultEncoder()), gotAttributeSet.Encoded(attribute.DefaultEncoder()))
316+
t.Errorf(
317+
"link[%v] has the wrong attributes; want %v, got %v",
318+
i,
319+
wantAttributeSet.Encoded(attribute.DefaultEncoder()),
320+
gotAttributeSet.Encoded(attribute.DefaultEncoder()),
321+
)
304322
}
305323
}
306324
}

bridge/opencensus/internal/tracer.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ func NewTracer(tracer trace.Tracer) octrace.Tracer {
2525

2626
// StartSpan starts a new child span of the current span in the context. If
2727
// there is no span in the context, it creates a new trace and span.
28-
func (o *Tracer) StartSpan(ctx context.Context, name string, s ...octrace.StartOption) (context.Context, *octrace.Span) {
28+
func (o *Tracer) StartSpan(
29+
ctx context.Context,
30+
name string,
31+
s ...octrace.StartOption,
32+
) (context.Context, *octrace.Span) {
2933
otelOpts, err := oc2otel.StartOptions(s)
3034
if err != nil {
3135
Handle(fmt.Errorf("starting span %q: %w", name, err))
@@ -36,7 +40,12 @@ func (o *Tracer) StartSpan(ctx context.Context, name string, s ...octrace.StartO
3640

3741
// StartSpanWithRemoteParent starts a new child span of the span from the
3842
// given parent.
39-
func (o *Tracer) StartSpanWithRemoteParent(ctx context.Context, name string, parent octrace.SpanContext, s ...octrace.StartOption) (context.Context, *octrace.Span) {
43+
func (o *Tracer) StartSpanWithRemoteParent(
44+
ctx context.Context,
45+
name string,
46+
parent octrace.SpanContext,
47+
s ...octrace.StartOption,
48+
) (context.Context, *octrace.Span) {
4049
// make sure span context is zeroed out so we use the remote parent
4150
ctx = trace.ContextWithSpan(ctx, nil)
4251
ctx = trace.ContextWithRemoteSpanContext(ctx, oc2otel.SpanContext(parent))
@@ -53,6 +62,8 @@ func (o *Tracer) NewContext(parent context.Context, s *octrace.Span) context.Con
5362
if otSpan, ok := s.Internal().(*Span); ok {
5463
return trace.ContextWithSpan(parent, otSpan.otelSpan)
5564
}
56-
Handle(fmt.Errorf("unable to create context with span %q, since it was created using a different tracer", s.String()))
65+
Handle(
66+
fmt.Errorf("unable to create context with span %q, since it was created using a different tracer", s.String()),
67+
)
5768
return parent
5869
}

bridge/opencensus/test/bridge_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,11 @@ func TestStartSpanWithRemoteParent(t *testing.T) {
9292
ctx := context.Background()
9393
ctx, parent := tracer.Start(ctx, "OpenTelemetrySpan1")
9494

95-
_, span := octrace.StartSpanWithRemoteParent(ctx, "OpenCensusSpan", ocbridge.OTelSpanContextToOC(parent.SpanContext()))
95+
_, span := octrace.StartSpanWithRemoteParent(
96+
ctx,
97+
"OpenCensusSpan",
98+
ocbridge.OTelSpanContextToOC(parent.SpanContext()),
99+
)
96100
span.End()
97101

98102
spans := sr.Ended()

bridge/opentracing/bridge.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,9 @@ type bridgeSetTracer struct {
283283
func (s *bridgeSetTracer) tracer() trace.Tracer {
284284
if !s.isSet {
285285
s.warnOnce.Do(func() {
286-
s.warningHandler("The OpenTelemetry tracer is not set, default no-op tracer is used! Call SetOpenTelemetryTracer to set it up.\n")
286+
s.warningHandler(
287+
"The OpenTelemetry tracer is not set, default no-op tracer is used! Call SetOpenTelemetryTracer to set it up.\n",
288+
)
287289
})
288290
}
289291
return s.otelTracer
@@ -362,7 +364,9 @@ func (t *BridgeTracer) baggageSetHook(ctx context.Context, list iBaggage.List) c
362364
}
363365
bSpan, ok := span.(*bridgeSpan)
364366
if !ok {
365-
t.warningHandler("Encountered a foreign OpenTracing span, will not propagate the baggage items from OpenTelemetry context\n")
367+
t.warningHandler(
368+
"Encountered a foreign OpenTracing span, will not propagate the baggage items from OpenTelemetry context\n",
369+
)
366370
return ctx
367371
}
368372
for k, v := range list {
@@ -374,12 +378,16 @@ func (t *BridgeTracer) baggageSetHook(ctx context.Context, list iBaggage.List) c
374378
func (t *BridgeTracer) baggageGetHook(ctx context.Context, list iBaggage.List) iBaggage.List {
375379
span := ot.SpanFromContext(ctx)
376380
if span == nil {
377-
t.warningHandler("No active OpenTracing span, can not propagate the baggage items from OpenTracing span context\n")
381+
t.warningHandler(
382+
"No active OpenTracing span, can not propagate the baggage items from OpenTracing span context\n",
383+
)
378384
return list
379385
}
380386
bSpan, ok := span.(*bridgeSpan)
381387
if !ok {
382-
t.warningHandler("Encountered a foreign OpenTracing span, will not propagate the baggage items from OpenTracing span context\n")
388+
t.warningHandler(
389+
"Encountered a foreign OpenTracing span, will not propagate the baggage items from OpenTracing span context\n",
390+
)
383391
return list
384392
}
385393
items := bSpan.extraBaggageItems
@@ -427,7 +435,9 @@ func (t *BridgeTracer) StartSpan(operationName string, opts ...ot.StartSpanOptio
427435
)
428436
if ot.SpanFromContext(checkCtx2) != nil {
429437
t.warnOnce.Do(func() {
430-
t.warningHandler("SDK should have deferred the context setup, see the documentation of go.opentelemetry.io/otel/bridge/opentracing/migration\n")
438+
t.warningHandler(
439+
"SDK should have deferred the context setup, see the documentation of go.opentelemetry.io/otel/bridge/opentracing/migration\n",
440+
)
431441
})
432442
}
433443
if hadTrueErrorTag {
@@ -473,7 +483,9 @@ func (t *BridgeTracer) ContextWithBridgeSpan(ctx context.Context, span trace.Spa
473483
func (t *BridgeTracer) ContextWithSpanHook(ctx context.Context, span ot.Span) context.Context {
474484
bSpan, ok := span.(*bridgeSpan)
475485
if !ok {
476-
t.warningHandler("Encountered a foreign OpenTracing span, will not run a possible deferred context setup hook\n")
486+
t.warningHandler(
487+
"Encountered a foreign OpenTracing span, will not run a possible deferred context setup hook\n",
488+
)
477489
return ctx
478490
}
479491
if bSpan.skipDeferHook {

0 commit comments

Comments
 (0)