Skip to content

Conversation

nagkumar91
Copy link
Contributor

@nagkumar91 nagkumar91 commented Oct 7, 2025

Description

Updates the previous barebones PR to include genai spans and traces.

Fixes # (issue)

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Testing

  • Manual agents example: cd instrumentation-genai/opentelemetry-instrumentation-openai-agents/examples/manual && cp .env.example .env (populate OPENAI_API_KEY, optional OTLP vars) then python3 main.py; confirmed travel response prints and spans export
    cleanly with integer timestamps.
  • Zero-code example: cd instrumentation-genai/opentelemetry-instrumentation-openai-agents/examples/zero-code && cp .env.example .env (set API key) then python3 main.py; verified auto-configured instrumentation loads env defaults and completes without
    exporter errors.
  • Unit tests: From repo root, with .venv active and pip install -e .[examples] applied, ran python3 -m pytest opentelemetry-instrumentation-openai-agents/tests/test_tracer.py; all tests passed, confirming span translation logic handles nanosecond
    timestamps and attribute mapping.

Environment

  • Python 3.9.6 inside the project’s .venv.
  • Dependencies installed via pip install -e instrumentation-genai/opentelemetry-instrumentation-openai-agents[examples].
  • OTLP collector optional; when unavailable, spans export successfully to the default console exporter.

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@nagkumar91 nagkumar91 marked this pull request as ready for review October 8, 2025 20:28
@nagkumar91 nagkumar91 requested a review from a team as a code owner October 8, 2025 20:28

def _operation_name(self, span_data: Any) -> str:
span_type = getattr(span_data, "type", None)
if span_type == "generation":
Copy link
Contributor

Choose a reason for hiding this comment

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

are these span_types always going to be in lowercase?


@property
def type(self) -> str:
return "function"
Copy link
Contributor

Choose a reason for hiding this comment

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

these strings like function, generation, etc. are being used in multiple places, can these be made constants instead of hardcoding the values.


processor = _OpenAIAgentsSpanProcessor(tracer=tracer, system=system)

tracing = _load_tracing_module()
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason why we are loading the module during init of the instrumentor and not at the beginning of runtime/

return value


def _get_registered_processors(provider) -> list:
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Include type annotations for provider and provide docstring on what the fields look like.

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.

6 participants