open-telemetry / opentelemetry-python-contrib

OpenTelemetry instrumentation for Python modules
https://opentelemetry.io
Apache License 2.0
739 stars 612 forks source link

openai: add behavior tests for span and logs disabled #3030

Open codefromthecrypt opened 2 days ago

codefromthecrypt commented 2 days ago

What problem do you want to solve?

As of semantic conventions 1.28, genai events are split from spans into log events. At the moment, there is code conflation about recording of both. For example, in some cases, event_logger.emit is guarded by span.is_recording(). We should probably have a coherent approach to recording prior to adding metrics.

Describe the solution you'd like

I think data accumulated to a span should be guarded on span.is_recording(), but independent from event_logger.emit, as logging could be enabled while tracing is disabled.

So, I would like to see tests of either span or events being disabled as well both enabled and both disabled.

Moreover, we may want to obviate creation of large strings when event_logger is NoOpEventLogger or effectively disabled. I don't see a function for is_recording and unsure if an event logger provider should return NoOpEventLogger when disabled. Whatever the expectations are, could be added to a PR on https://github.com/open-telemetry/opentelemetry-python to change the python code documentation.

Describe alternatives you've considered

If for simplicitly we want to only emit log events when spans are also, that's fine but should be documented and tested.

Additional Context

No response

Would you like to implement a fix?

None