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

Allow SENTRY_TRACE and SENTRY_BAGGAGE env vars to continue traces #2179

Closed

Conversation

natikgadzhi
Copy link
Contributor

Summary

This pull request is part 3 of #2056. It adds support for continuing traces by passing SENTRY_TRACE and SENTRY_BAGGAGE environment variables.

Closes #2099.

Changes

  • I've renamed Baggage.from_header to be Baggage.from_baggage_string and ditto for traces, just for readability.
  • Added ENV vars support and unit tests.
  • Added a changelog entry.

Reviewing

I'm new to distributed tracing, and Sentry implementation in particular, so I might need more handholding with the next few PRs.

In #2056:

You may update the traceId and dynamicSamplingContext from the request headers during an incoming request or if the process was exposed to a SENTRY_TRACE and/or SENTRY_BAGGAGE environment variable if performance is disabled.

In my current implementation, if the trace string was not passed in headers otherwise, PropagationContext will try and read the environment variable. It does NOT check whether Sentry Performance is enabled. Is that correct?

/cc @sl0thentr0py

Copy link

codecov bot commented Nov 24, 2023

Codecov Report

Merging #2179 (2a9fa67) into master (c4e4797) will decrease coverage by 0.03%.
The diff coverage is 100.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2179      +/-   ##
==========================================
- Coverage   97.34%   97.31%   -0.03%     
==========================================
  Files          99       99              
  Lines        3687     3687              
==========================================
- Hits         3589     3588       -1     
- Misses         98       99       +1     
Components Coverage Δ
sentry-ruby 98.03% <100.00%> (ø)
sentry-rails 94.98% <ø> (ø)
sentry-sidekiq 94.50% <ø> (ø)
sentry-resque 92.06% <ø> (-1.59%) ⬇️
sentry-delayed_job 94.44% <ø> (ø)
sentry-opentelemetry 100.00% <100.00%> (ø)
Files Coverage Δ
...entelemetry/lib/sentry/opentelemetry/propagator.rb 100.00% <100.00%> (ø)
sentry-ruby/lib/sentry/baggage.rb 100.00% <100.00%> (ø)
sentry-ruby/lib/sentry/propagation_context.rb 100.00% <100.00%> (ø)
sentry-ruby/lib/sentry/transaction.rb 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

@natikgadzhi
Copy link
Contributor Author

@st0012 if you feel like reviewing another one, this should be a quick and clean one.

Copy link
Collaborator

@st0012 st0012 left a comment

Choose a reason for hiding this comment

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

I left a few comments but I don't have much context on this part of tracing, so it's safer for @sl0thentr0py to give another review.


# Trace string could be passed from the invoking code,
# or via the environment variable.
sentry_trace_string = env["HTTP_SENTRY_TRACE"] || env[SENTRY_TRACE_HEADER_NAME] || ENV["SENTRY_TRACE"]
Copy link
Collaborator

@st0012 st0012 Nov 25, 2023

Choose a reason for hiding this comment

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

I may be wrong, but I don't think the "environment variables" here means the system environment variables. It likely means request envs too?

@@ -26,11 +26,11 @@ def initialize(items, mutable: true)
#
# @param header [String] The incoming Baggage header string.
# @return [Baggage, nil]
def self.from_incoming_header(header)
def self.from_baggage_string(baggage_string)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure if this method is supposed to be public or not. If it is public for users, we can't simply rename it as it'll break users' apps.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, you're right. Even if it's not public by design, folks might be using it. I could either make a deprecated wrapper with the old name and keep the new name, or revert the rename, either are fine by me.

@natikgadzhi
Copy link
Contributor Author

natikgadzhi commented Nov 25, 2023 via email

Copy link
Contributor Author

@natikgadzhi natikgadzhi left a comment

Choose a reason for hiding this comment

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

Welp, I actually think I messed up and by "read trace from environment" we didn't mean OS env. In other SDKs (php, Python, etc), most instrumentations only pass request environment.

@@ -26,11 +26,11 @@ def initialize(items, mutable: true)
#
# @param header [String] The incoming Baggage header string.
# @return [Baggage, nil]
def self.from_incoming_header(header)
def self.from_baggage_string(baggage_string)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, you're right. Even if it's not public by design, folks might be using it. I could either make a deprecated wrapper with the old name and keep the new name, or revert the rename, either are fine by me.

@natikgadzhi natikgadzhi closed this Jan 1, 2024
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.

Add a mechanism to continue a trace from environment variables.
2 participants