openllmetry icon indicating copy to clipboard operation
openllmetry copied to clipboard

🐛 Bug Report: No way to set `use_legacy_attributes` using TraceLoop.init()

Open josephwangrb opened this issue 4 months ago • 5 comments

Which component is this bug for?

OpenAI Instrumentation

📜 Description

What's the issue?

Although most of the instrumentors support the flag use_legacy_attributes to emit prompts input&output as events, there is no way to pass this flag through TraceLoop.init().

People have to init traceProvider, logProvider, metricProvider manually, and list down all the instrumentors that are needed.

# 1. Define Resource
resource = Resource(attributes={SERVICE_NAME: "ying-test"})

# 2. configure trace provider
tracer_provider = TracerProvider(resource=resource)
trace.set_tracer_provider(tracer_provider)
span_exporter = OTLPSpanExporterHTTP(endpoint="http://127.0.0.1:4320/v1/traces")
tracer_provider.add_span_processor(BatchSpanProcessor(span_exporter))

# 3 configure log provider
logger_provider = LoggerProvider(resource=resource)
_logs.set_logger_provider(logger_provider)
log_exporter = OTLPLogExporterHTTP(endpoint="http://127.0.0.1:4320/v1/logs")
logger_provider.add_log_record_processor(BatchLogRecordProcessor(log_exporter))

OpenAIInstrumentor(
    use_legacy_attributes=False,
).instrument(
    event_logger_provider=EventLoggerProvider()
)

What's the root cause?

  1. The function Traceloop.init() does not allow this flag as an argument.
  2. When we init instrumentors here, there is no parameter for use_legacy_attributes.

Why is this a Bug rather than feature request?

As we have closed this issue, people expect this feature is supported through TraceLoop whereas it is not due to no way to configure it.

👟 Reproduction steps

When we tried to send input&output as event, we met this issue.

👍 Expected behavior

Traceloop.init(use_legacy_attributes=False)

👎 Actual Behavior with Screenshots

# 1. Define Resource
resource = Resource(attributes={SERVICE_NAME: "ying-test"})

# 2. configure trace provider
tracer_provider = TracerProvider(resource=resource)
trace.set_tracer_provider(tracer_provider)
span_exporter = OTLPSpanExporterHTTP(endpoint="http://127.0.0.1:4320/v1/traces")
tracer_provider.add_span_processor(BatchSpanProcessor(span_exporter))

# 3 configure log provider
logger_provider = LoggerProvider(resource=resource)
_logs.set_logger_provider(logger_provider)
log_exporter = OTLPLogExporterHTTP(endpoint="http://127.0.0.1:4320/v1/logs")
logger_provider.add_log_record_processor(BatchLogRecordProcessor(log_exporter))

OpenAIInstrumentor(
    use_legacy_attributes=False,
).instrument(
    event_logger_provider=EventLoggerProvider()
)

🤖 Python Version

No response

📃 Provide any additional context for the Bug.

Please also advice how should we create the EventLoggerProvider? should we set it as an argument for Traceloop.init or, we just create it when use_legacy_attributes is set to False.

👀 Have you spent some time to check if this bug has been raised before?

  • [x] I checked and didn't find similar issue

Are you willing to submit PR?

Yes I am willing to submit a PR!

josephwangrb avatar Aug 07 '25 00:08 josephwangrb

Thanks @josephwangrb! Yes, let's add it as an argument to Traceloop.init. BTW, since the upcoming decision for GenAI otel semconv is to support both events and attributes - let's change the name to be use_attributes (or use_events) - the attributes is no longer consider legacy.

nirga avatar Aug 07 '25 14:08 nirga

Hey @nirga, can I get assigned on this one? I'll implement the attribute on my free time 😄

LuizDMM avatar Aug 25 '25 12:08 LuizDMM

Sure! @LuizDMM Btw I'd rename this to be "use events" or something

nirga avatar Aug 25 '25 13:08 nirga

Makes sense, only on Traceloop.init or at the instrumentations as well? @nirga

LuizDMM avatar Aug 25 '25 13:08 LuizDMM

on the instrumentation as well

nirga avatar Aug 25 '25 13:08 nirga