-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add span adjuster that moves some OTel Resource attributes to S…
…pan.Process (#4844) ## Which problem is this PR solving? - Resolves #4534 ## Description of the changes - Apply OTel resource discovery(detectors) since OTel has plenty of detectors under the hood. Link https://pkg.go.dev/go.opentelemetry.io/otel/[email protected]/resource - Add OTel tags to process tags adjuster and we need to adjust only `otel.libray.name` and `otel.library.version`. Found here https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/adf5bb501bc65d24ae48088bde37f3c0b13353d0/pkg/translator/jaeger/traces_to_jaegerproto.go#L172 - Bump all OTel semconv to v1.21.0 since telemetrySDK detector use v1.21.0 semconv. ## How was this change tested? - Added a new unit test for the adjuster - Tested manual in local by running `set OTEL_EXPORTER_OTLP_ENDPOINT http://localhost:4318; go run main.go all --otel-exporter=otlp` and `make run-all-in-one`, and ordered a ride in HotROD app. <img width="1440" alt="image" src="https://github.com/jaegertracing/jaeger/assets/46216691/57220ac9-ec60-40ef-a903-ee815a36dbdf"> ## Checklist - [x] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [x] I have signed all commits - [x] I have added unit tests for the new functionality - [x] I have run lint and test steps successfully - for `jaeger`: `make lint test` - for `jaeger-ui`: `yarn lint` and `yarn test` --------- Signed-off-by: James Ryans <[email protected]> Signed-off-by: James Ryans <[email protected]> Co-authored-by: Yuri Shkuro <[email protected]>
- Loading branch information
1 parent
065cc55
commit c0e4ff1
Showing
12 changed files
with
169 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (c) 2023 The Jaeger Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package adjuster | ||
|
||
import ( | ||
semconv "go.opentelemetry.io/otel/semconv/v1.21.0" | ||
|
||
"github.com/jaegertracing/jaeger/model" | ||
) | ||
|
||
var otelLibraryKeys = map[string]struct{}{ | ||
string(semconv.OTelLibraryNameKey): {}, | ||
string(semconv.OTelLibraryVersionKey): {}, | ||
} | ||
|
||
func OTelTagAdjuster() Adjuster { | ||
adjustSpanTags := func(span *model.Span) { | ||
newI := 0 | ||
for i, tag := range span.Tags { | ||
if _, ok := otelLibraryKeys[tag.Key]; ok { | ||
span.Process.Tags = append(span.Process.Tags, tag) | ||
continue | ||
} | ||
if i != newI { | ||
span.Tags[newI] = tag | ||
} | ||
newI++ | ||
} | ||
span.Tags = span.Tags[:newI] | ||
} | ||
|
||
return Func(func(trace *model.Trace) (*model.Trace, error) { | ||
for _, span := range trace.Spans { | ||
adjustSpanTags(span) | ||
model.KeyValues(span.Process.Tags).Sort() | ||
} | ||
return trace, nil | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// Copyright (c) 2023 The Jaeger Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package adjuster | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
semconv "go.opentelemetry.io/otel/semconv/v1.21.0" | ||
|
||
"github.com/jaegertracing/jaeger/model" | ||
) | ||
|
||
func TestOTelTagAdjuster(t *testing.T) { | ||
testCases := []struct { | ||
description string | ||
span *model.Span | ||
expected *model.Span | ||
}{ | ||
{ | ||
description: "span with otel library tags", | ||
span: &model.Span{ | ||
Tags: model.KeyValues{ | ||
model.String("random_key", "random_value"), | ||
model.String(string(semconv.OTelLibraryNameKey), "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"), | ||
model.String(string(semconv.OTelLibraryVersionKey), "0.45.0"), | ||
model.String("another_key", "another_value"), | ||
}, | ||
Process: &model.Process{ | ||
Tags: model.KeyValues{}, | ||
}, | ||
}, | ||
expected: &model.Span{ | ||
Tags: model.KeyValues{ | ||
model.String("random_key", "random_value"), | ||
model.String("another_key", "another_value"), | ||
}, | ||
Process: &model.Process{ | ||
Tags: model.KeyValues{ | ||
model.String(string(semconv.OTelLibraryNameKey), "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"), | ||
model.String(string(semconv.OTelLibraryVersionKey), "0.45.0"), | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
description: "span without otel library tags", | ||
span: &model.Span{ | ||
Tags: model.KeyValues{ | ||
model.String("random_key", "random_value"), | ||
}, | ||
Process: &model.Process{ | ||
Tags: model.KeyValues{}, | ||
}, | ||
}, | ||
expected: &model.Span{ | ||
Tags: model.KeyValues{ | ||
model.String("random_key", "random_value"), | ||
}, | ||
Process: &model.Process{ | ||
Tags: model.KeyValues{}, | ||
}, | ||
}, | ||
}, | ||
} | ||
for _, testCase := range testCases { | ||
t.Run(testCase.description, func(t *testing.T) { | ||
beforeTags := testCase.span.Tags | ||
|
||
trace := &model.Trace{ | ||
Spans: []*model.Span{testCase.span}, | ||
} | ||
trace, err := OTelTagAdjuster().Adjust(trace) | ||
assert.NoError(t, err) | ||
assert.Equal(t, testCase.expected.Tags, trace.Spans[0].Tags) | ||
assert.Equal(t, testCase.expected.Process.Tags, trace.Spans[0].Process.Tags) | ||
|
||
newTag := model.String("new_key", "new_value") | ||
beforeTags[0] = newTag | ||
assert.Equal(t, newTag, testCase.span.Tags[0], "span.Tags still points to the same underlying array") | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters