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

Update backend to use Traces 0.14.1 #2

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jedschneider
Copy link

@jedschneider jedschneider commented Jan 5, 2025

PR to start to address #1 but I know this still needs a lot of work.

Types of Changes

  • Bug fix.
  • New feature.
  • Breaking change.
  • Maintenance.

Contribution

Copy link
Author

@jedschneider jedschneider left a comment

Choose a reason for hiding this comment

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

@ioquatix Happy New Year!

I realize this PR is not ready for merge, but I think I'm a bit stuck on it. I am using the Datadog backend in production, but would like this backend to function in situations where Datadog is unavailable. There's probably a lot more that you'd want to do to bump this gem: I noticed in the datadog backend you're using sus and i believe rubocop for linting. I'm happy to help bring it up to speed with the other backends, just need some guidance, thanks!

@@ -33,7 +33,7 @@ module OpenTelemetry
TRACER = ::OpenTelemetry.tracer_provider.tracer(Traces::Backend::OpenTelemetry.name, Traces::Backend::OpenTelemetry::VERSION)

module Interface
def trace(name, attributes: nil, &block)
def trace(name, attributes: {}, &block)
Copy link
Author

Choose a reason for hiding this comment

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

attributes calls transform_keys below, which nil will not respond to.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that makes sense, alternatively we could write attributes&.transform_keys. Not sure what makes more sense.

@@ -44,18 +44,18 @@ def trace(name, attributes: nil, &block)
end
rescue Exception => error
span&.record_exception(error)
span&.status = ::OpenTelemetry::Traces::Status.error("Unhandled exception of type: #{error.class}")
span&.status = ::OpenTelemetry::Trace::Status.error("Unhandled exception of type: #{error.class}")
Copy link
Author

Choose a reason for hiding this comment

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

appears to be a namespace change within OpenTelemetry

if span_context = span.context
state = baggage.values(context: span.context)
Copy link
Author

Choose a reason for hiding this comment

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

state was an unused variable and the baggage api has changed, if this is important I need to understand the otel baggage concept and implement.

Copy link
Member

Choose a reason for hiding this comment

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

I don't think it's important. The goal is to create a context which can be sent over the wire, e.g. over an HTTP request or encoded into a database query comment etc.

Comment on lines +71 to +59
flags = 0

if span_context.trace_flags.sampled?
flags |= Context::SAMPLED
end
Copy link
Author

Choose a reason for hiding this comment

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

I pulled this from the Datadog Backend. as it was implemented, the trace flags were expected to be provided as an integer, not an object.

Comment on lines 89 to 93
Traces.trace_context = new_context
expect(instance.my_span.context).to have_attributes(
trace_id: new_context.trace_id,
span_id: new_context.parent_id
)
Copy link
Author

Choose a reason for hiding this comment

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

I tried to keep this spec file as similar as possible to the datadog backend spec given the differences between sus and rspec i might have missed some things but i did my best. I assume that would be preferred.

this specific spec is failing, because as far as i can tell, the trace context is not being updated with the fake context provided under test. However, I'm not exactly sure this is the intended behavior. I need some feedback here to understand what specific feature this is supporting.

Comment on lines 112 to 113
# It's updated on the next call to trace:
expect(span.context.trace_id).not_to eq(new_context.trace_id)
Copy link
Author

Choose a reason for hiding this comment

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

ditto on this spec, its failing, but I think my assertions are correct assuming i understand the feature supported.

@ioquatix
Copy link
Member

ioquatix commented Jan 5, 2025

Thanks for working on this.

Maybe we can do a 2-phase update. Firstly, let me rework the testing and update the gem code, then we can fix the open telemetry integration issues.

I don't personally use Otel, so it would be good to have your guidance and feedback on those changes, along with any PRs you are willing to contribute (including this one, thanks!).

@ioquatix
Copy link
Member

ioquatix commented Jan 5, 2025

Okay, I've modernised the main branch, do you mind rebasing on that? Sorry for then churn.

@ioquatix
Copy link
Member

I've updated as much of the tests to incorporate your feedback, excluding the parts we don't know if they work or not. Please update the PR.

I think that in order for the test assertions to work, OpenTelemetry might need to be put into a test mode, in order for us to track actual context assignment, and parent spans, etc.

@ioquatix
Copy link
Member

I've added support for in_span and attach which I think works as we expect. Can you please try it out?

@ioquatix ioquatix added this to the v0.2.0 milestone Jan 11, 2025
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.

2 participants