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

tracing: use opentracing.GlobalTracer instead of globalTracer #635

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

redloaf
Copy link
Contributor

@redloaf redloaf commented Nov 10, 2023

💸 TL;DR

There are some places where globalTracer is referenced instead of the opentracing.GlobalTracer(). If these ever differ (which is entirely possible), this breaks assumptions about how this library integrates with opentracing.

📜 Details

If nil is passed as the tracer to newTrace (which is incredibly common), use opentracing's global tracer instead of baseplate's.

🧪 Testing Steps / Validation

✅ Checks

  • CI tests (if present) are passing
  • Adheres to code style for repo
  • Contributor License Agreement (CLA) completed if not a Reddit employee

@redloaf redloaf requested a review from a team as a code owner November 10, 2023 00:47
@redloaf redloaf requested review from fishy, kylelemons, konradreiche and marcoferrer and removed request for a team November 10, 2023 00:47
tracing/trace.go Outdated Show resolved Hide resolved
tracing/trace.go Show resolved Hide resolved
tracing/trace.go Outdated
@@ -159,7 +181,10 @@ func (t *trace) publish(ctx context.Context) error {
if !t.shouldSample() || t.tracer == nil {
return nil
}
return t.tracer.Record(ctx, t.toZipkinSpan())
if tracer := t.getTracer(); tracer != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This means if you override the global tracer with one that's not a *Tracer, no spans are ever published.

Copy link
Member

Choose a reason for hiding this comment

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

aren't we actually trying to override it with a different tracer implementation? isn't it going to break a lot of things?

can you provide a high level explanation on how the library would work with the new tracer implementation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is actually the behavior we desire. If you provide a tracer that is not a *Tracer, then tracer.Record is never called. However, presumably whatever tracer you do provide would record its spans and export them. Applying these changes makes this library compatible with other opentracing tracers, such as the opentracing bridge for opentelemetry, which will not be a *Tracer but would likely record and ship spans using an OTLP trace exporter.

@konradreiche konradreiche removed their request for review November 10, 2023 21:49
@redloaf redloaf requested review from kylelemons and fishy and removed request for fishy May 8, 2024 19:22
s.trace.tracer.logger.Log(ctx, msg+err.Error())
if tracer := s.trace.internalTracer(); tracer != nil {
tracer.logger.Log(ctx, msg+err.Error())
}
Copy link
Contributor

Choose a reason for hiding this comment

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

in the interest of fallbacks, should this also do something if internalTracer isn't found? like fall back to the global logger?

Why does this inject its own logger anyway? 🤔

Comment on lines +58 to +61
if tracer, ok := t.tracer.(*Tracer); ok && tracer != nil {
return tracer
}
return nil
Copy link
Contributor

Choose a reason for hiding this comment

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

don't return nil in-band, that's a recipe for nil pointer dereferences. Return *Tracer, bool

@@ -91,8 +118,8 @@ func (t *trace) toZipkinSpan() ZipkinSpan {
zs.Duration = timebp.DurationMicrosecond(end.Sub(t.start))

var endpoint ZipkinEndpointInfo
if t.tracer != nil {
endpoint = t.tracer.endpoint
if tracer := t.internalTracer(); tracer != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if tracer := t.internalTracer(); tracer != nil {
if tracer, ok := t.internalTracer(); ok {

(see comment above about returning a bool too)

// This function expects a *tracing.Tracer, but the global opentracing.Tracer may not be one.
// That's why it's relying on the globalTracer: even if the opentracing.GlobalTracer() has been overridden,
// the IDs generated by baseplate will still conform to the specified configuration.
traceID = globalTracer.newTraceID()
Copy link
Contributor

Choose a reason for hiding this comment

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

if we're not using globalTracer as a tracer, can we shield it somehow so that it only exposes the methods we want to be used on it, so it can't accidentally get missed again?

Copy link
Member

@fishy fishy left a comment

Choose a reason for hiding this comment

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

I think we want to take a step back here.

AFAIK we no longer have any infra to handle the zipkin tracing data any more, so the whole tracing package is not working. trying to keep it "working" isn't really worth the effort IMHO.

If the intention here is "let's make the tracing package interop with the new tracing infra and works to emit new traces", then we should redesign the API around how new tracing system works (with opentelemetry or whatever), and just mark whatever old API that no longer making sense as deprecated, instead of trying to "keep them working".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants