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

[PROF-9163] Fix missing profiling code hotspots when using ddtrace+otel #3466

Merged
merged 2 commits into from
Feb 21, 2024

Conversation

ivoanjo
Copy link
Member

@ivoanjo ivoanjo commented Feb 20, 2024

What does this PR do?

This PR fixes the profiler not sending code hotspots data when ddtrace is being used with OpenTelemetry (e.g. when following these instructions).

Note that in particular this only works in apps that use

require 'datadog/opentelemetry'

Motivation:

Since in this mode, otel data goes through ddtrace, code hotspots should be correctly supported. The only reason this didn't work is that otel spans were handled slightly differently, and the profiler was not correctly accounting for this.

Additional Notes:

N/A

How to test the change?

I've updated the Rakefile to run the profiler test suite with and without opentelemetry, and added test coverage for this.

To test it manually, you can add gem 'opentelemetry-sdk' to your Gemfile, and the specs will run.

Here's also a trivial app you can use for testing:

require 'opentelemetry/sdk'
require 'datadog/opentelemetry'

OpenTelemetry::SDK.configure
MyAppTracer = OpenTelemetry.tracer_provider.tracer('otel-testing')
MyAppTracer.in_span("do_work") do |span|
  sleep 2
end

**What does this PR do?**

This PR fixes the profiler not sending code hotspots data when
ddtrace is being used with OpenTelemetry (e.g. [when following these
instructions](https://docs.datadoghq.com/tracing/trace_collection/custom_instrumentation/otel_instrumentation/ruby/)).

Note that in particular this only works in apps that use

```ruby
require 'datadog/opentelemetry'
```

**Motivation:**

Since in this mode, otel data goes through ddtrace, code hotspots
should be correctly supported. The only reason this didn't work is
that otel spans were handled slightly differently, and the
profiler was not correctly accounting for this.

**Additional Notes:**

N/A

**How to test the change?**

I've updated the `Rakefile` to run the profiler test suite with and
without opentelemetry, and added test coverage for this.

To test it manually, you can add `gem 'opentelemetry-sdk'` to your
Gemfile, and the specs will run.

Here's also a trivial app you can use for testing:

```ruby
require 'opentelemetry/sdk'
require 'datadog/opentelemetry'

OpenTelemetry::SDK.configure
MyAppTracer = OpenTelemetry.tracer_provider.tracer('otel-testing')
MyAppTracer.in_span("do_work") do |span|
  sleep 2
end
```
@ivoanjo ivoanjo requested review from a team as code owners February 20, 2024 19:27
@github-actions github-actions bot added the profiling Involves Datadog profiling label Feb 20, 2024
Copy link
Contributor

@AlexJF AlexJF left a comment

Choose a reason for hiding this comment

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

LGTM and nice test coverage!

@ivoanjo ivoanjo merged commit daa00e2 into master Feb 21, 2024
220 checks passed
@ivoanjo ivoanjo deleted the ivoanjo/prof-9163-fix-otel-code-hotspots branch February 21, 2024 13:23
@github-actions github-actions bot added this to the 2.0 milestone Feb 21, 2024
@ivoanjo ivoanjo modified the milestones: 2.0, 1.21.0 Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
profiling Involves Datadog profiling
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants