opentelemetry-python-contrib
opentelemetry-python-contrib copied to clipboard
Provide a way for Logs SDK to sample based on span context
trafficstars
The OpenAI instrumentation currently only records events if the span is recording:
https://github.com/open-telemetry/opentelemetry-python-contrib/blob/2756c1edff42db2984296e0c5dbe668e8de85aa8/instrumentation-genai/opentelemetry-instrumentation-openai-v2/src/opentelemetry/instrumentation/openai_v2/patch.py#L59-L63
This makes sense, since event recording can be quite expensive and we can piggyback on the sampling decision. However it feels like the Logging API should be more integrated and instrumentation shouldn't need to do these checks. Most logging libraries also have an API to check if recording like Logger.isEnabledFor() and/or support lazy evaluation of log fields. So two questions are
- Should GenAI events be recorded only when a span is recording?
- Should the instrumentation be in charge of this or should the Logging SDK provide its own API to check for recording or lazily evaluate log entry fields.