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

Sentry.set_user should work with OpenTelemetry #2171

Closed
sbeckeriv opened this issue Nov 15, 2023 · 3 comments · Fixed by getsentry/sentry-docs#8829
Closed

Sentry.set_user should work with OpenTelemetry #2171

sbeckeriv opened this issue Nov 15, 2023 · 3 comments · Fixed by getsentry/sentry-docs#8829

Comments

@sbeckeriv
Copy link

Issue Description

I have a rails 6 server with ruby 2.7. I must have 5.12 installed with the sentry rails to match. I have turned on performance (spans) recently. I wanted more information so i am following https://docs.sentry.io/platforms/ruby/performance/instrumentation/opentelemetry/ i have found that my Sentry.set_user data did not continue to work after moving over to opentelmetry.

After switching over the ui for performance shows ? for the user id.

Reproduction Steps

I do not have one. I am calling set_user in a normal controller flow. My configuration matches the doc https://docs.sentry.io/platforms/ruby/performance/instrumentation/opentelemetry/

Expected Behavior

I would expect set_user to report the user while using the OpenTelemetry configuration.

Actual Behavior

No user data is set. you can see event.user is empty in before_send_transaction callback.

Ruby Version

2.7

SDK Version

5.12

Integration and Its Version

Rails 6

Sentry Config

https://docs.sentry.io/platforms/ruby/performance/instrumentation/opentelemetry/ matches my configuration.

@sl0thentr0py
Copy link
Member

note to self: this is likely because of some scope lifecycle shenanigans, try a repro and see how to fix

@sl0thentr0py
Copy link
Member

hey @sbeckeriv this is due to how our scope management works, can you add the following in your opentelemetry initializer (where you configure the span_processor)?

Rails.application.config.middleware.move_after(
  Sentry::Rails::CaptureExceptions,
  OpenTelemetry::Instrumentation::Rack::Middlewares::TracerMiddleware
)

For now please use this, we have a longer plan to revamp our scope management completely so I don't want to mess with the current system too much. I will also add this to the documentation.

@mtomov
Copy link

mtomov commented Jan 11, 2024

Hi @sl0thentr0py ,

I think that with the switch to using Rack Events, this has stopped working again

https://github.com/open-telemetry/opentelemetry-ruby-contrib/tree/main/instrumentation/rack#rack-middleware-vs-rack-events
open-telemetry/opentelemetry-ruby-contrib#342

I disabled the Rack events, to re-enable the middleware:

OpenTelemetry::SDK.configure do |config|
  config.use_all({
    "OpenTelemetry::Instrumentation::Rack" => {use_rack_events: false}
  })
  config.add_span_processor(Sentry::OpenTelemetry::SpanProcessor.instance)
end

Rails.application.config.middleware.move_after(
  Sentry::Rails::CaptureExceptions,
  OpenTelemetry::Instrumentation::Rack::Middlewares::TracerMiddleware
)

which got the user association to work : )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants