open-telemetry / open-telemetry/opentelemetry-java

Being able to associate resources with spans and not only a with a tracer

Open
#4,645 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

blocked:spec Feature Request
Dominant language
Java
Stars
2.5k
Forks
1k
Avg merge
3d 17h
Merged PRs (30d)
58

Description

Is your feature request related to a problem? Please describe.
I would like to create spans and associate custom resources to that span. Currently I cannot call setResource() on the span builder to achieve this. Instead internally the resource associated with the tracer is used and can only be overridden on tracer level. In my case I do not have microservices but kind of virtual processes (not physical ones represented as threads) and do not want to create separate tracers for each virtual process (could be thounsands). Instead I would like to share the tracer and just adapt the resource on span creation.

Describe the solution you'd like.
I would like to have a setResource() method on span builder to set the resource used.

Describe alternatives you've considered.
As a workaround I am using setAccessible() on the resource field of a span.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Java SDK's SpanBuilder and the existing tracer-level resource handling. Trace how a span receives its resource and determine the expected precedence when a builder resource is set. Done means SpanBuilder exposes setResource() and spans created with it use the supplied resource without requiring separate tracers.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
observability-sre
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.