Skip to content

Guidance around using OTel for tracing in language SDKs #971

Open
@cartermp

Description

@cartermp

Something that's come up a few times in feedback channels for me was that it can be unclear which part of the API to use for which scenario.

For example, consider the following API usages in .NET:

using var span1 = tracer.StartSpan("one");

//...

using var span2 = tracer.StartActiveSpan("two");

and in Java:

Span span1 = tracer.spanBuilder("parent").startSpan();

//...

Span span2 = tracer.spanBuilder("parent").startSpan();
span2.makeCurrent();

Which is the "right" thing to do? Well, if you dig through some issues, you'll stumble on this comment: open-telemetry/opentelemetry-specification#469 (comment)

Couple examples wehn you need to start but not active the span:

  • In case when you starting multiple async operations - you don't want to set any one of them as active on the current thread. So you pass the started span as an argument to the async callback to set as active there.
  • When you want to save on tls operations and/or have custom thread pool managing logic.

Really great advice here. And the unwritten, implicit guidance here is:

you're mostly likely going to want to use StartActiveSpan for anything other than specialized scenarios like this.

In the Java docs there is this statement:

The OpenTelemetry API offers also an automated way to propagate the parent span on the current thread:

This is factual, but the question in my mind is: "Okay, but which approach should I generally use?"

Guidance will differ from language to language because their SDKs have different patterns. But I think this will be critical to document for OTel to succeed in the long term.

What other kinds of guidance can be written for language SDKs?

Some I can think of:

  • Recommended way to create spans in a trace, including child/nested spans
  • Recommended way to store metadata in a trace (set attributes on spans vs. store in baggage and propagate, write a span processor, etc?)
  • Recommended way to configure an exporter if applicable (this tripped me up in go before)
  • Recommended way to wire up automatic instrumentation (always use it? turn on as much as possible? etc.)
  • Recommended approaches to sampling data based on that data (I imagine this could get punted for now)
  • How to name tracer/span/attributes/baggage

Metadata

Metadata

Assignees

Labels

discussionInput from everyone is helpful to drive this forwarddocse4-monthsEffort: 1+ months

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions