getsentry / sentry-ruby

Sentry SDK for Ruby
https://sentry.io/for/ruby
MIT License
927 stars 486 forks source link

OpenTelemetry: "connect" spans from SDK are included in traces #2338

Open flood4life opened 1 month ago

flood4life commented 1 month ago

Issue Description

We are looking into using the OpenTelemetry instrumenter for collecting traces, and our preliminary tests showed traces with a lot of connect spans:

image

Upon closer inspection, we found that they're coming from the Sentry SDK:

image

It was somewhat surprising, because Sentry SpanProcessor is supposed to filter them out: https://github.com/getsentry/sentry-ruby/blob/master/sentry-opentelemetry/lib/sentry/opentelemetry/span_processor.rb#L82-L98

Then we found out that Net::HTTP OTEL instrumentation can produce both HTTP connect and connect spans: https://github.com/open-telemetry/opentelemetry-ruby-contrib/blob/b26b765b91b789bce25d47743326d3cc16b6feb7/instrumentation/net_http/lib/opentelemetry/instrumentation/net/http/patches/instrumentation.rb#L62-L68

However, Sentry SpanProcessor will apply that logic only for spans with names starting with "HTTP".

For now, we have solved it internally by monkey-patching

if otel_span.name.start_with?("HTTP")

to

if otel_span.name.start_with?("HTTP") || otel_span.name == "connect"

And that seems to have resolved the issue for us, but this felt like something that belongs upstream.

Reproduction Steps

Follow this guide: https://docs.sentry.io/platforms/ruby/tracing/instrumentation/opentelemetry/

Expected Behavior

Internal "connect" spans are not reported, just like internal "HTTP" spans

Actual Behavior

Internal "connect" spans are reported, unlike the internal "HTTP" spans

Ruby Version

3.3.1

SDK Version

5.16.1

Integration and Its Version

No response

Sentry Config

No response

sl0thentr0py commented 3 weeks ago

thx @flood4life will fix this