Skip to content

library-based alternative to opentelemetry-instrument for easy integration in Jupyter notebooksΒ #3263

@codefromthecrypt

Description

@codefromthecrypt

What problem do you want to solve?

Right now, we have a zero code solution: opentelemetry-instrument which is great as it removes the cruft of setting up various components, especially if your instrumentation uses multiple signals like logs, metrics and tracing.

However, as this wraps python itself, it presents integration problems which show up in certain scenarios like debuggers and Jupyter notebooks.

Describe the solution you'd like

I would like to see such a "quick start" that works the same as the CLI, but doesn't require bootstrapping python.

from opentelemetry.sdk import AutoInstrument
AutoInstrument.init()

Describe alternatives you've considered

I see some code on github doing this:

from opentelemetry.instrumentation.auto_instrumentation.sitecustomize import initialize
initialize()

which is incorrect as it redundantly initializing, and should be like this instead.

import opentelemetry.instrumentation.auto_instrumentation.sitecustomize

However, for this to work you must set PYTHONPATH (e.g. PYTHONPATH=$PWD dotenv run -- python chat.py), or you get an error until PR 2886 is resolved.

As the import name is neither intuitive, nor documented and has a pending PR to make it usable by default, it isn't yet an ideal solution. If it were (possibly renamed or at least) documented, and the PYTHONPATH glitch cleared, it could close this issue.

Additional Context

3rd party otel SDKs such as openllmetry and langtrace have a library alternative where you include a single initialization comment in your main.py, and that reads ENV variables such as opentelemetry-instrument does.

langtrace:

from langtrace_python_sdk import langtrace
langtrace.init(api_key='<your_api_key>') # Get your API key at langtrace.ai

openllmetry:

from traceloop.sdk import Traceloop
Traceloop.init()

This solves the problem, and I can verify that with the correct settings it works for any OTLP endpoint. However, as you notice these are branded and vendor specific. Also, there are configuration differences as well instrumentation choices.

Would you like to implement a fix?

None

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions