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

ddtrace/opentelemetry: Introduced OTel name remapping #2337

Merged
merged 26 commits into from
Nov 13, 2023

Conversation

dianashevchenko
Copy link
Contributor

@dianashevchenko dianashevchenko commented Nov 7, 2023

What does this PR do?

This PR adds calculating of the operation name based on the OTel attributes and span kind.

Motivation

The OTel API only has the concept of a single name associated with a span, which in Datadog is represented as the “resource name”. However, Datadog has an additional name, the span’s “operation name”, which serves important functions such as metrics calculation, which is used for customer monitoring and alerting setups. Since the OTel API doesn’t have an equivalent for an operation name, we must calculate one.

Reviewer's Checklist

  • Changed code has unit tests for its functionality at or near 100% coverage.
  • There is a benchmark for any new code, or changes to existing code.
  • If this interacts with the agent in a new way, a system test has been added.

For Datadog employees:

  • If this PR touches code that handles credentials of any kind, such as Datadog API keys, I've requested a review from @DataDog/security-design-and-guidance.
  • This PR doesn't touch any of that.

Unsure? Have a question? Request a review!

ddtrace/opentelemetry/span.go Outdated Show resolved Hide resolved
ddtrace/opentelemetry/span.go Outdated Show resolved Hide resolved
@pr-commenter
Copy link

pr-commenter bot commented Nov 7, 2023

Benchmarks

Benchmark execution time: 2023-11-13 15:35:46

Comparing candidate commit 99ab227 in PR branch shevchenko/otel-name-remapping with baseline commit 0ab4465 in branch main.

Found 0 performance improvements and 3 performance regressions! Performance is the same for 36 metrics, 2 unstable metrics.

scenario:BenchmarkOTelApiWithCustomTags/otel_api-24

  • 🟥 allocated_mem [+863 bytes; +879 bytes] or [+21.754%; +22.144%]
  • 🟥 allocations [+10; +10] or [+29.412%; +29.412%]
  • 🟥 execution_time [+1.407µs; +1.523µs] or [+23.075%; +24.979%]

@dianashevchenko
Copy link
Contributor Author

dianashevchenko commented Nov 7, 2023

I rerun the test suit, including APM_TRACING_E2E_OTEL and failed tests in Parametric, with the system tests branch DataDog/system-tests#1804. All pass

Copy link
Contributor

@knusbaum knusbaum left a comment

Choose a reason for hiding this comment

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

It would be nice to be able to remove nameSet and avoid branching if we can.

ddtrace/opentelemetry/span.go Outdated Show resolved Hide resolved
ddtrace/opentelemetry/span.go Outdated Show resolved Hide resolved
ddtrace/opentelemetry/span.go Outdated Show resolved Hide resolved
Co-authored-by: Kyle Nusbaum <kyle@datadog.com>
ddtrace/opentelemetry/span.go Outdated Show resolved Hide resolved
ddtrace/opentelemetry/span.go Outdated Show resolved Hide resolved
ddtrace/opentelemetry/span.go Outdated Show resolved Hide resolved
ddtrace/opentelemetry/span.go Outdated Show resolved Hide resolved
ddtrace/opentelemetry/span.go Outdated Show resolved Hide resolved
ddtrace/opentelemetry/span.go Outdated Show resolved Hide resolved
@dianashevchenko dianashevchenko marked this pull request as ready for review November 10, 2023 17:00
@dianashevchenko dianashevchenko requested a review from a team November 10, 2023 17:00
ddtrace/opentelemetry/span.go Outdated Show resolved Hide resolved
ddtrace/opentelemetry/span.go Outdated Show resolved Hide resolved
Comment on lines 49 to 57
for k, v := range s.attributes {
// if we find operation.name,
if k == operationNameKey || k == ext.SpanName {
// set it and keep track that it was set to ignore everything else
if name, ok := v.(string); ok {
s.attributes[ext.SpanName] = strings.ToLower(name)
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Refactoring suggestion:
Similar to the Java pseudocode in the doc, you can just check for an operation.name attribute in the converter function, and return out early if it exists.
If you do that, then this entire loop can disappear.

i.e. the only changes you need in this entire function then are:

	s.SetName(s.createOperationName())
	for k, v := range s.attributes {
		s.SetTag(k, v)
	}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, what do you mean by converter function ?

Copy link
Contributor

Choose a reason for hiding this comment

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

By "converter function" I meant the createOperationName method you have.

ddtrace/opentelemetry/span.go Outdated Show resolved Hide resolved
ddtrace/opentelemetry/span.go Show resolved Hide resolved
ddtrace/opentelemetry/span.go Outdated Show resolved Hide resolved
ddtrace/opentelemetry/span_test.go Outdated Show resolved Hide resolved
ddtrace/opentelemetry/tracer.go Outdated Show resolved Hide resolved
ddtrace/opentelemetry/tracer.go Outdated Show resolved Hide resolved
ddtrace/opentelemetry/tracer.go Outdated Show resolved Hide resolved
Copy link
Contributor

@katiehockman katiehockman left a comment

Choose a reason for hiding this comment

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

Just two last questions, thanks!

ddtrace/opentelemetry/tracer.go Outdated Show resolved Hide resolved
ddtrace/opentelemetry/span.go Outdated Show resolved Hide resolved
@katiehockman katiehockman enabled auto-merge (squash) November 13, 2023 19:52
@katiehockman katiehockman merged commit 5d0b85b into main Nov 13, 2023
49 of 51 checks passed
@katiehockman katiehockman deleted the shevchenko/otel-name-remapping branch November 13, 2023 19:59
@darccio darccio restored the shevchenko/otel-name-remapping branch November 16, 2023 10:18
@darccio darccio deleted the shevchenko/otel-name-remapping branch November 16, 2023 10:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants