You've already forked opentelemetry-go
mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-11-25 22:41:46 +02:00
Add the golines golangci-lint formatter (#6513)
Ensure consistent line wrapping (<= 120 characters) within the project.
This commit is contained in:
@@ -151,7 +151,10 @@ func (ts *testSampler) ShouldSample(p SamplingParameters) SamplingResult {
|
||||
if strings.HasPrefix(p.Name, ts.prefix) {
|
||||
decision = RecordAndSample
|
||||
}
|
||||
return SamplingResult{Decision: decision, Attributes: []attribute.KeyValue{attribute.Int("callCount", ts.callCount)}}
|
||||
return SamplingResult{
|
||||
Decision: decision,
|
||||
Attributes: []attribute.KeyValue{attribute.Int("callCount", ts.callCount)},
|
||||
}
|
||||
}
|
||||
|
||||
func (ts testSampler) Description() string {
|
||||
@@ -374,13 +377,21 @@ func TestStartSpanNewRootNotSampled(t *testing.T) {
|
||||
|
||||
_, s2 := neverSampledTr.Start(ctx, "span2-no-newroot")
|
||||
if !s2.SpanContext().IsSampled() {
|
||||
t.Error(fmt.Errorf("got child span is not sampled, want child span with sampler: ParentBased(NeverSample()) to be sampled"))
|
||||
t.Error(
|
||||
fmt.Errorf(
|
||||
"got child span is not sampled, want child span with sampler: ParentBased(NeverSample()) to be sampled",
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
// Adding WithNewRoot causes child spans to not sample based on parent context
|
||||
_, s3 := neverSampledTr.Start(ctx, "span3-newroot", trace.WithNewRoot())
|
||||
if s3.SpanContext().IsSampled() {
|
||||
t.Error(fmt.Errorf("got child span is sampled, want child span WithNewRoot() and with sampler: ParentBased(NeverSample()) to not be sampled"))
|
||||
t.Error(
|
||||
fmt.Errorf(
|
||||
"got child span is sampled, want child span WithNewRoot() and with sampler: ParentBased(NeverSample()) to not be sampled",
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -731,8 +742,12 @@ func TestLinks(t *testing.T) {
|
||||
k2v2 := attribute.String("key2", "value2")
|
||||
k3v3 := attribute.String("key3", "value3")
|
||||
|
||||
sc1 := trace.NewSpanContext(trace.SpanContextConfig{TraceID: trace.TraceID([16]byte{1, 1}), SpanID: trace.SpanID{3}})
|
||||
sc2 := trace.NewSpanContext(trace.SpanContextConfig{TraceID: trace.TraceID([16]byte{1, 1}), SpanID: trace.SpanID{3}})
|
||||
sc1 := trace.NewSpanContext(
|
||||
trace.SpanContextConfig{TraceID: trace.TraceID([16]byte{1, 1}), SpanID: trace.SpanID{3}},
|
||||
)
|
||||
sc2 := trace.NewSpanContext(
|
||||
trace.SpanContextConfig{TraceID: trace.TraceID([16]byte{1, 1}), SpanID: trace.SpanID{3}},
|
||||
)
|
||||
|
||||
l1 := trace.Link{SpanContext: sc1, Attributes: []attribute.KeyValue{k1v1}}
|
||||
l2 := trace.Link{SpanContext: sc2, Attributes: []attribute.KeyValue{k2v2, k3v3}}
|
||||
@@ -773,9 +788,15 @@ func TestLinks(t *testing.T) {
|
||||
func TestLinksOverLimit(t *testing.T) {
|
||||
te := NewTestExporter()
|
||||
|
||||
sc1 := trace.NewSpanContext(trace.SpanContextConfig{TraceID: trace.TraceID([16]byte{1, 1}), SpanID: trace.SpanID{3}})
|
||||
sc2 := trace.NewSpanContext(trace.SpanContextConfig{TraceID: trace.TraceID([16]byte{1, 1}), SpanID: trace.SpanID{3}})
|
||||
sc3 := trace.NewSpanContext(trace.SpanContextConfig{TraceID: trace.TraceID([16]byte{1, 1}), SpanID: trace.SpanID{3}})
|
||||
sc1 := trace.NewSpanContext(
|
||||
trace.SpanContextConfig{TraceID: trace.TraceID([16]byte{1, 1}), SpanID: trace.SpanID{3}},
|
||||
)
|
||||
sc2 := trace.NewSpanContext(
|
||||
trace.SpanContextConfig{TraceID: trace.TraceID([16]byte{1, 1}), SpanID: trace.SpanID{3}},
|
||||
)
|
||||
sc3 := trace.NewSpanContext(
|
||||
trace.SpanContextConfig{TraceID: trace.TraceID([16]byte{1, 1}), SpanID: trace.SpanID{3}},
|
||||
)
|
||||
|
||||
sl := NewSpanLimits()
|
||||
sl.LinkCountLimit = 2
|
||||
@@ -951,7 +972,12 @@ func startNamedSpan(tp *TracerProvider, trName, name string, args ...trace.SpanS
|
||||
// passed name and with the passed context. The context is returned
|
||||
// along with the span so this parent can be used to create child
|
||||
// spans.
|
||||
func startLocalSpan(ctx context.Context, tp *TracerProvider, trName, name string, args ...trace.SpanStartOption) (context.Context, trace.Span) {
|
||||
func startLocalSpan(
|
||||
ctx context.Context,
|
||||
tp *TracerProvider,
|
||||
trName, name string,
|
||||
args ...trace.SpanStartOption,
|
||||
) (context.Context, trace.Span) {
|
||||
ctx, span := tp.Tracer(trName).Start(
|
||||
ctx,
|
||||
name,
|
||||
@@ -1299,8 +1325,21 @@ func TestRecordErrorWithStackTrace(t *testing.T) {
|
||||
assert.Equal(t, got.events[0].Attributes[1].Value.AsString(), want.events[0].Attributes[1].Value.AsString())
|
||||
gotStackTraceFunctionName := strings.Split(got.events[0].Attributes[2].Value.AsString(), "\n")
|
||||
|
||||
assert.Truef(t, strings.HasPrefix(gotStackTraceFunctionName[1], "go.opentelemetry.io/otel/sdk/trace.recordStackTrace"), "%q not prefixed with go.opentelemetry.io/otel/sdk/trace.recordStackTrace", gotStackTraceFunctionName[1])
|
||||
assert.Truef(t, strings.HasPrefix(gotStackTraceFunctionName[3], "go.opentelemetry.io/otel/sdk/trace.(*recordingSpan).RecordError"), "%q not prefixed with go.opentelemetry.io/otel/sdk/trace.(*recordingSpan).RecordError", gotStackTraceFunctionName[3])
|
||||
assert.Truef(
|
||||
t,
|
||||
strings.HasPrefix(gotStackTraceFunctionName[1], "go.opentelemetry.io/otel/sdk/trace.recordStackTrace"),
|
||||
"%q not prefixed with go.opentelemetry.io/otel/sdk/trace.recordStackTrace",
|
||||
gotStackTraceFunctionName[1],
|
||||
)
|
||||
assert.Truef(
|
||||
t,
|
||||
strings.HasPrefix(
|
||||
gotStackTraceFunctionName[3],
|
||||
"go.opentelemetry.io/otel/sdk/trace.(*recordingSpan).RecordError",
|
||||
),
|
||||
"%q not prefixed with go.opentelemetry.io/otel/sdk/trace.(*recordingSpan).RecordError",
|
||||
gotStackTraceFunctionName[3],
|
||||
)
|
||||
}
|
||||
|
||||
func TestRecordErrorNil(t *testing.T) {
|
||||
@@ -1346,7 +1385,11 @@ func TestWithSpanKind(t *testing.T) {
|
||||
}
|
||||
|
||||
if spanData.SpanKind() != trace.SpanKindInternal {
|
||||
t.Errorf("Default value of Spankind should be Internal: got %+v, want %+v\n", spanData.SpanKind(), trace.SpanKindInternal)
|
||||
t.Errorf(
|
||||
"Default value of Spankind should be Internal: got %+v, want %+v\n",
|
||||
spanData.SpanKind(),
|
||||
trace.SpanKindInternal,
|
||||
)
|
||||
}
|
||||
|
||||
sks := []trace.SpanKind{
|
||||
@@ -1397,9 +1440,15 @@ func TestWithResource(t *testing.T) {
|
||||
want: resource.Default(),
|
||||
},
|
||||
{
|
||||
name: "explicit resource",
|
||||
options: []TracerProviderOption{WithResource(resource.NewSchemaless(attribute.String("rk1", "rv1"), attribute.Int64("rk2", 5)))},
|
||||
want: mergeResource(t, resource.Environment(), resource.NewSchemaless(attribute.String("rk1", "rv1"), attribute.Int64("rk2", 5))),
|
||||
name: "explicit resource",
|
||||
options: []TracerProviderOption{
|
||||
WithResource(resource.NewSchemaless(attribute.String("rk1", "rv1"), attribute.Int64("rk2", 5))),
|
||||
},
|
||||
want: mergeResource(
|
||||
t,
|
||||
resource.Environment(),
|
||||
resource.NewSchemaless(attribute.String("rk1", "rv1"), attribute.Int64("rk2", 5)),
|
||||
),
|
||||
},
|
||||
{
|
||||
name: "last resource wins",
|
||||
@@ -1407,12 +1456,22 @@ func TestWithResource(t *testing.T) {
|
||||
WithResource(resource.NewSchemaless(attribute.String("rk1", "vk1"), attribute.Int64("rk2", 5))),
|
||||
WithResource(resource.NewSchemaless(attribute.String("rk3", "rv3"), attribute.Int64("rk4", 10))),
|
||||
},
|
||||
want: mergeResource(t, resource.Environment(), resource.NewSchemaless(attribute.String("rk3", "rv3"), attribute.Int64("rk4", 10))),
|
||||
want: mergeResource(
|
||||
t,
|
||||
resource.Environment(),
|
||||
resource.NewSchemaless(attribute.String("rk3", "rv3"), attribute.Int64("rk4", 10)),
|
||||
),
|
||||
},
|
||||
{
|
||||
name: "overlapping attributes with environment resource",
|
||||
options: []TracerProviderOption{WithResource(resource.NewSchemaless(attribute.String("rk1", "rv1"), attribute.Int64("rk5", 10)))},
|
||||
want: mergeResource(t, resource.Environment(), resource.NewSchemaless(attribute.String("rk1", "rv1"), attribute.Int64("rk5", 10))),
|
||||
name: "overlapping attributes with environment resource",
|
||||
options: []TracerProviderOption{
|
||||
WithResource(resource.NewSchemaless(attribute.String("rk1", "rv1"), attribute.Int64("rk5", 10))),
|
||||
},
|
||||
want: mergeResource(
|
||||
t,
|
||||
resource.Environment(),
|
||||
resource.NewSchemaless(attribute.String("rk1", "rv1"), attribute.Int64("rk5", 10)),
|
||||
),
|
||||
},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
@@ -1527,8 +1586,18 @@ func TestSpanCapturesPanicWithStackTrace(t *testing.T) {
|
||||
assert.Equal(t, "error message", spans[0].Events()[0].Attributes[1].Value.AsString())
|
||||
|
||||
gotStackTraceFunctionName := strings.Split(spans[0].Events()[0].Attributes[2].Value.AsString(), "\n")
|
||||
assert.Truef(t, strings.HasPrefix(gotStackTraceFunctionName[1], "go.opentelemetry.io/otel/sdk/trace.recordStackTrace"), "%q not prefixed with go.opentelemetry.io/otel/sdk/trace.recordStackTrace", gotStackTraceFunctionName[1])
|
||||
assert.Truef(t, strings.HasPrefix(gotStackTraceFunctionName[3], "go.opentelemetry.io/otel/sdk/trace.(*recordingSpan).End"), "%q not prefixed with go.opentelemetry.io/otel/sdk/trace.(*recordingSpan).End", gotStackTraceFunctionName[3])
|
||||
assert.Truef(
|
||||
t,
|
||||
strings.HasPrefix(gotStackTraceFunctionName[1], "go.opentelemetry.io/otel/sdk/trace.recordStackTrace"),
|
||||
"%q not prefixed with go.opentelemetry.io/otel/sdk/trace.recordStackTrace",
|
||||
gotStackTraceFunctionName[1],
|
||||
)
|
||||
assert.Truef(
|
||||
t,
|
||||
strings.HasPrefix(gotStackTraceFunctionName[3], "go.opentelemetry.io/otel/sdk/trace.(*recordingSpan).End"),
|
||||
"%q not prefixed with go.opentelemetry.io/otel/sdk/trace.(*recordingSpan).End",
|
||||
gotStackTraceFunctionName[3],
|
||||
)
|
||||
}
|
||||
|
||||
func TestReadOnlySpan(t *testing.T) {
|
||||
@@ -1930,7 +1999,9 @@ func TestSpanAddLink(t *testing.T) {
|
||||
name: "AddLinkWithInvalidSpanContext",
|
||||
attrLinkCountLimit: 128,
|
||||
link: trace.Link{
|
||||
SpanContext: trace.NewSpanContext(trace.SpanContextConfig{TraceID: trace.TraceID([16]byte{}), SpanID: [8]byte{}}),
|
||||
SpanContext: trace.NewSpanContext(
|
||||
trace.SpanContextConfig{TraceID: trace.TraceID([16]byte{}), SpanID: [8]byte{}},
|
||||
),
|
||||
},
|
||||
want: &snapshot{
|
||||
name: "span0",
|
||||
|
||||
Reference in New Issue
Block a user