Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add span adjuster that moves some OTel Resource attributes to Span.Process #4844

Merged
merged 7 commits into from
Oct 16, 2023

Conversation

james-ryans
Copy link
Contributor

@james-ryans james-ryans commented Oct 15, 2023

Which problem is this PR solving?

Description of the changes

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.
image

Checklist

Signed-off-by: James Ryans <james.ryans2012@gmail.com>
Signed-off-by: James Ryans <james.ryans2012@gmail.com>
@james-ryans james-ryans requested a review from a team as a code owner October 15, 2023 17:49
@codecov
Copy link

codecov bot commented Oct 15, 2023

Codecov Report

All modified lines are covered by tests ✅

Files Coverage Δ
cmd/query/app/querysvc/adjusters.go 100.00% <100.00%> (ø)
examples/hotrod/pkg/tracing/rpcmetrics/observer.go 70.00% <ø> (ø)
model/adjuster/otel_tag.go 100.00% <100.00%> (ø)
plugin/metrics/prometheus/metricsstore/reader.go 100.00% <ø> (ø)
plugin/storage/cassandra/spanstore/reader.go 100.00% <ø> (ø)

📢 Thoughts on this report? Let us know!.

}

func OTelTagAdjuster() Adjuster {
return Func(func(trace *model.Trace) (*model.Trace, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: please move to a helper function to reduce nesting (you have 5 levels of indentation)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved it to an anonymous function

func OTelTagAdjuster() Adjuster {
return Func(func(trace *model.Trace) (*model.Trace, error) {
for _, span := range trace.Spans {
filteredTags := make([]model.KeyValue, 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to be mindful of allocations & perf overhead. I liked this in-place approach better: https://github.com/jaegertracing/jaeger/pull/4841/files#diff-ca36bdd0bff9f5671449689223699d0029147f11212f797269850af1585aab21R46

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optimized it

Copy link
Member

@yurishkuro yurishkuro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@yurishkuro yurishkuro changed the title Fix OTEL missing and wrong place process tags feat: Add span adjuster that moves some OTel Resource attributes to Span.Process Oct 15, 2023
Signed-off-by: James Ryans <james.ryans2012@gmail.com>
yurishkuro
yurishkuro previously approved these changes Oct 15, 2023
@yurishkuro
Copy link
Member

is this change breaking HotROD somehow? The integration test failed several times

@james-ryans
Copy link
Contributor Author

is this change breaking HotROD somehow? The integration test failed several times

Looking into it.. it works normally in my local

Signed-off-by: James Ryans <james.ryans2012@gmail.com>
@james-ryans
Copy link
Contributor Author

Okay, so I've ran the example/hotrod-integration-test.sh locally and logged the example-hotrod container, turns out that the resource.WithHostID() caused the error since the HotROD docker container was built using distroless base image but the resourrce.WithHostID() trying to read from /etc/machine-id or /var/lib/dbus/machine-id file.

2023-10-15T19:01:09.599Z	INFO	cobra@v1.7.0/command.go:970	Using Prometheus as metrics backend
2023-10-15T19:01:09.599Z	INFO	cobra@v1.7.0/command.go:940	Starting all services
2023-10-15T19:01:09.600Z	FATAL	tracing/init.go:73	resource creation failed	{"service": "customer", "error": "1 errors occurred detecting resource:\n\t* host id not found in: /etc/machine-id or /var/lib/dbus/machine-id"}
github.com/jaegertracing/jaeger/examples/hotrod/pkg/tracing.InitOTEL
	github.com/jaegertracing/jaeger/examples/hotrod/pkg/tracing/init.go:73
github.com/jaegertracing/jaeger/examples/hotrod/services/customer.NewServer
	github.com/jaegertracing/jaeger/examples/hotrod/services/customer/server.go:44
github.com/jaegertracing/jaeger/examples/hotrod/cmd.glob..func2
	github.com/jaegertracing/jaeger/examples/hotrod/cmd/customer.go:37

So, for this example, I'll just remove the resource.HostID() detector which the traces will not have host.id process tags.

@james-ryans
Copy link
Contributor Author

Actually, I haven't added the OTel builtin detectors to jaeger components, should I add them? If yes, can you tell me which detector is needed?

@yurishkuro
Copy link
Member

ran the example/hotrod-integration-test.sh locally and logged the example-hotrod container

Yeah, this should've been automated -- #4845

Actually, I haven't added the OTel builtin detectors to jaeger components, should I add them? If yes, can you tell me which detector is needed?

Same ones are fine, but let's do it in a separate PR

model/adjuster/otel_tag_test.go Show resolved Hide resolved
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest adding this sort of test to ensure that Span.tags slice has not been re-allocated: https://go.dev/play/p/euEi6j19DXN

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm.. do you have in mind on how to test this? 🤔 I actually can't find out how to ensure this, or can you give me an actual test case?

Copy link
Member

@yurishkuro yurishkuro Oct 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty much like in the example I pointed to. Before L83 store a reference to beforeTags := testCase.span.Tags slice. After Adjust is called:

newTag := model.String("new tag", "new value")
beforeTags[0] = newTag
assert.Equal(t, newTag, testCase.span.Tags[0], "span.Tags still points to the same underlying array")

The assert confirms that beforeTags and testCase.span.Tags still point to the same underlying slice.
You can even add

assert.NotEqual(t, beforeTags, testCase.span.Tags)

Copy link
Contributor Author

@james-ryans james-ryans Oct 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, now I get what you meant. I've added the test, but I don't think assert.NotEqual(t, beforeTags, testCase.span.Tags) works since beforeTags and testCase.span.Tags point to the same underlying slice?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they point to the same underlying array, but the slices are different - the one after the adjustment is shorter

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh right..

yurishkuro added a commit that referenced this pull request Oct 15, 2023
## Which problem is this PR solving?
- The HotROD CIT was failing in #4844, but no logs were shown to
understand why

## Description of the changes
- Run container with `--name example-hotrod`
- Add `docker logs example-hotrod` to CIT workflow in case of failure

Signed-off-by: Yuri Shkuro <github@ysh.us>
james-ryans and others added 3 commits October 16, 2023 06:56
Co-authored-by: Yuri Shkuro <yurishkuro@users.noreply.github.com>
Signed-off-by: James Ryans <46216691+james-ryans@users.noreply.github.com>
Signed-off-by: James Ryans <james.ryans2012@gmail.com>
Signed-off-by: James Ryans <james.ryans2012@gmail.com>
@yurishkuro yurishkuro merged commit c0e4ff1 into jaegertracing:main Oct 16, 2023
31 checks passed
@yurishkuro yurishkuro added the changelog:new-feature Change that should be called out as new feature in CHANGELOG label Oct 17, 2023
yurishkuro added a commit that referenced this pull request Oct 19, 2023
## Which problem is this PR solving?
- Resolves #4534
- Continuation from #4844

## Description of the changes
- Add OTel resources to Jaeger components and tracegen tool.

## How was this change tested?
- Tested manually in local
<img width="1440" alt="image"
src="https://github.com/jaegertracing/jaeger/assets/46216691/28bfb121-0c5a-42b1-a3e3-2c5915c90b17">
<img width="1440" alt="image"
src="https://github.com/jaegertracing/jaeger/assets/46216691/3b6d993a-2fac-4c65-97c2-e3dca581a3a1">


## Checklist
- [x] I have read
https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md
- [x] I have signed all commits
- [ ] 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 <james.ryans2012@gmail.com>
Co-authored-by: Yuri Shkuro <yurishkuro@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:new-feature Change that should be called out as new feature in CHANGELOG
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[OTEL] Process info is missing from the spans
2 participants