Skip to content

Genesis LLO Support in ADOT SDK #361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: genesis-dev-v2
Choose a base branch
from

Conversation

yiyuan-he
Copy link
Contributor

@yiyuan-he yiyuan-he commented May 12, 2025

What does this pull request do?

Adds support to handle LLO from third-party instrumentation SDKs in ADOT SDK.

The following SDKs are supported:

  • Traceloop/Openllmetry
  • OpenInference
  • OpenLit

Note: OTel dependencies in ADOT SDK have been loosened as a short-term workaround to support the various conflicting dependency requirements of third-party instrumentation SDKs.

Test plan

Built this custom ADOT SDK into various sample apps and exported the span and logs data to the OTLP X-Ray and Logs endpoint, respectively, to validate the LLO extraction and transformation to Gen AI Events.

Configurations tested:

  • LangChain + Traceloop/Openllmetry
  • LangChan + OpenInference
  • LangChain + OpenLit
  • CrewAI + Traceloop/Openllmetry
  • CrewAI + OpenInference
  • CrewAI + OpenLit

Environment variable configuration:

λ  env OTEL_METRICS_EXPORTER=none \
       OTEL_TRACES_EXPORTER=otlp \
       OTEL_LOGS_EXPORTER=otlp \
       OTEL_PYTHON_DISTRO=aws_distro \
       OTEL_PYTHON_CONFIGURATOR=aws_configurator \
       OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf \
       OTEL_EXPORTER_OTLP_LOGS_HEADERS="x-aws-log-group=test,x-aws-log-stream=default" \
       OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=https://xray.us-east-1.amazonaws.com/v1/traces \
       OTEL_EXPORTER_OTLP_LOGS_ENDPOINT=https://logs.us-east-1.amazonaws.com/v1/logs \
       OTEL_RESOURCE_ATTRIBUTES="service.name=langchain-app" \
       OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED="true" \
       OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT="true" \
       OTEL_PYTHON_DISABLED_INSTRUMENTATIONS="http,sqlalchemy,psycopg2,pymysql,sqlite3,aiopg,asyncpg,mysql_connector,botocore,boto3,urllib3,requests,starlette" \
       AGENT_OBSERVABILITY_ENABLED="true" \
       python app.py

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@yiyuan-he yiyuan-he requested a review from a team as a code owner May 12, 2025 20:54
@yiyuan-he yiyuan-he force-pushed the genesis-llo-extraction-dev-v2 branch from afd727c to 49069e2 Compare May 12, 2025 20:57
@yiyuan-he yiyuan-he force-pushed the genesis-llo-extraction-dev-v2 branch from 49069e2 to f4e93d6 Compare May 12, 2025 21:14
@yiyuan-he yiyuan-he changed the base branch from genesis_dev to main May 12, 2025 21:14
@yiyuan-he yiyuan-he force-pushed the genesis-llo-extraction-dev-v2 branch from dbc0fcf to d04f786 Compare May 15, 2025 20:11
@yiyuan-he yiyuan-he changed the base branch from main to genesis_dev May 16, 2025 03:08
@yiyuan-he yiyuan-he changed the base branch from genesis_dev to main May 16, 2025 03:09
@yiyuan-he yiyuan-he changed the base branch from main to genesis-dev-v2 May 16, 2025 03:10
@yiyuan-he yiyuan-he changed the title Genesis LLO Handling [WIP] Genesis LLO Handling May 16, 2025
"""
events = []
span_ctx = span.context
gen_ai_system = span.attributes.get("traceloop.entity.name", "unknown")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gen_ai.system is not always available in the span. This is a best attempt at still retrieving a relevant value.

Comment on lines +228 to +233
all_events = []
all_events.extend(self._extract_gen_ai_prompt_events(span, attributes, event_timestamp))
all_events.extend(self._extract_gen_ai_completion_events(span, attributes, event_timestamp))
all_events.extend(self._extract_traceloop_events(span, attributes, event_timestamp))
all_events.extend(self._extract_openlit_span_event_attributes(span, attributes, event_timestamp))
all_events.extend(self._extract_openinference_attributes(span, attributes, event_timestamp))
Copy link
Contributor Author

@yiyuan-he yiyuan-he May 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Support for more third-party SDKs can be added by following this pattern.

I don't think we can go further with isolating these rules since there is no consistent and generic way to determine which SDK family is being instrumented. Also, many of these third-party SDKs may have overlapping rules for generic OTel attributes such as gen_ai.prompt.{n}.content and gen_ai.completion.{n}.content.

Comment on lines +166 to +169
logging_enabled = os.getenv(_OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED, "false")
if logging_enabled.strip().lower() == "true":
_init_logging(log_exporters, resource)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed order of pipeline initialization so we can pass the global logger provider instance to the span pipeline if AGENT_OBSERVABILITY_ENABLED flag is enabled.

import sys
from logging import Logger, getLogger

import pkg_resources

_logger: Logger = getLogger(__name__)

AGENT_OBSERVABILITY_ENABLED = "AGENT_OBSERVABILITY_ENABLED"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LLO handling is gated behind this configuration. If false, then the ADOT SDK will have default behavior in span and logs pipelines.

@yiyuan-he yiyuan-he changed the title Genesis LLO Handling Genesis LLO Support in ADOT SDK May 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant