Attributes passed to get_tracer() do not appear in spans
Describe your environment
OS: MacOS Python version: Python 3.11.13 SDK version: 1.39.1 API version: 1.39.1
What happened?
I find attributes parameter of TracerProvider.get_tracer() documented as
Specifies the attributes of the emitted telemetry.
I expect the attributes passed here will appear in every trace created by the tracer, but cannot see the behavior. What do I miss to do or misunderstand?
Steps to Reproduce
Based on the example https://opentelemetry.io/docs/languages/python/getting-started/#traces I added attributes parameter:
from random import randint
from flask import Flask
from opentelemetry import trace
# Acquire a tracer
tracer = trace.get_tracer("diceroller.tracer", attributes={"attr-name":"attr-value"})
app = Flask(__name__)
@app.route("/rolldice")
def roll_dice():
return str(roll())
def roll():
# This creates a new span that's the child of the current one
with tracer.start_as_current_span("roll") as rollspan:
res = randint(1, 6)
rollspan.set_attribute("roll.value", res)
return res
Expected Result
{"attr-name":"attr-value"} appears in the generated span
Actual Result
Cannot see {"attr-name":"attr-value"} in the generated span
Additional context
No response
Would you like to implement a fix?
No
Tip
React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.
attributes Specifies the instrumentation scope attributes to associate with emitted telemetry, refer to https://opentelemetry.io/docs/specs/otel/trace/api/#get-a-tracer
Thank you for the more specific documentation.
If I want to ensure that every span from a specific tracer has specific customer.id attribute, is this the right way to have multiple TracerProviders per customer ID and set the customer ID as resource of the TracerProvider?
I was assuming each tracer's attributes could be used for that purpose with single TracerProvider, but it seems not.
Typically something like customer id would be different each time the traced code runs, so you wouldn't want to associate a single tracer with a customer. I would expect customer id to be a span attribute.
Outside of the specific use case, what you did with scope attributes does work too, but it's possible your trace backend/database just doesn't surface the scope attributes. For example here's how it looks in otel-tui