Skip to content

feat: install() one-call setup helper (v1.3.0)#13

Merged
prathamesh-sonpatki merged 3 commits intomainfrom
feat/install-helper
Apr 26, 2026
Merged

feat: install() one-call setup helper (v1.3.0)#13
prathamesh-sonpatki merged 3 commits intomainfrom
feat/install-helper

Conversation

@prathamesh-sonpatki
Copy link
Copy Markdown
Member

Summary

  • Adds last9_genai.install() — a single call that wires up the full Last9
    GenAI observability pipeline: providers, Last9SpanProcessor,
    Last9LogToSpanProcessor, the capture-content env var, and
    OpenAIInstrumentor().instrument() (when the openai-v2 package is
    installed).
  • Returns an InstallHandle dataclass so callers can reach the providers
    (to attach exporters) and call shutdown().
  • Bumps version to 1.3.0.

Why

Previously customers had to repeat six lines of boilerplate (see README
"Manual wiring" section) to hook up the log-to-span bridge. That was the
friction Avakash hit. install() compresses that to:

from last9_genai import install
handle = install()

Test plan

  • 9 new unit tests for install() — provider reuse, env-var behaviour,
    kwarg forwarding, shutdown, missing-openai-v2 fallback.
  • 148 tests pass on py3.14.
  • Black clean.
  • Post-merge: tag v1.3.0 and verify PyPI publish.

Related

  • v1.2.0 (agent_context) shipped on PyPI earlier today.
  • Follows the design sketched in the session notes for bundling log-bridge
    setup into the package.

🤖 Generated with Claude Code

Collapses the usual six-line setup (TracerProvider + Last9SpanProcessor +
LoggerProvider + Last9LogToSpanProcessor + OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT
env + OpenAIInstrumentor.instrument()) into a single `install()` call.

The helper:
- creates the providers if the caller didn't pass any, and optionally
  registers them as OTel globals (set_global=True by default)
- wires Last9SpanProcessor + Last9LogToSpanProcessor together so span and
  log pipelines share state
- sets OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT unless the
  caller already set it
- best-effort calls OpenAIInstrumentor().instrument(logger_provider=...)
  if opentelemetry-instrumentation-openai-v2 is importable
- returns an InstallHandle dataclass exposing both providers, both
  processors, and a shutdown() convenience

Also forwards cost-tracking kwargs (custom_pricing, enable_cost_tracking,
workflow_tracker) through to Last9SpanProcessor so install() is a full
replacement for the manual wiring.

Bumps version to 1.3.0.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Comment thread tests/test_install.py Fixed
Comment thread tests/test_install.py Fixed
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Comment thread tests/test_install.py Fixed
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@prathamesh-sonpatki
Copy link
Copy Markdown
Member Author

@coderabbitai do full review

@prathamesh-sonpatki prathamesh-sonpatki merged commit ba18f8b into main Apr 26, 2026
7 checks passed
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