diff --git a/docs/conf.py b/docs/conf.py index 4b2bda04a8..2570e22b2a 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -40,6 +40,13 @@ if isdir(join(instr, f)) ] +instr_genai = "../instrumentation-genai" +instr_genai_dirs = [ + os.path.abspath("/".join(["../instrumentation-genai", f, "src"])) + for f in listdir(instr) + if isdir(join(instr, f)) +] + prop = "../propagator" prop_dirs = [ os.path.abspath("/".join([prop, f, "src"])) @@ -60,7 +67,7 @@ for f in listdir(resource) if isdir(join(resource, f)) ] -sys.path[:0] = exp_dirs + instr_dirs + sdk_ext_dirs + prop_dirs + resource_dirs +sys.path[:0] = exp_dirs + instr_dirs + instr_genai_dirs + sdk_ext_dirs + prop_dirs + resource_dirs # -- Project information ----------------------------------------------------- diff --git a/docs/index.rst b/docs/index.rst index e2bf32e12e..f9144c5209 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -24,7 +24,7 @@ installed separately via pip: pip install opentelemetry-instrumentation-{instrumentation} pip install opentelemetry-sdk-extension-{sdk-extension} -A complete list of packages can be found at the +A complete list of packages can be found at the `Contrib repo instrumentation `_ and `Contrib repo exporter `_ directories. @@ -50,6 +50,7 @@ install cd opentelemetry-python-contrib pip install -e ./instrumentation/opentelemetry-instrumentation-flask pip install -e ./instrumentation/opentelemetry-instrumentation-botocore + pip install -e ./instrumentation-genai/opentelemetry-instrumentation-openai-v2 pip install -e ./sdk-extension/opentelemetry-sdk-extension-aws pip install -e ./resource/opentelemetry-resource-detector-container @@ -62,6 +63,14 @@ install instrumentation/** +.. toctree:: + :maxdepth: 2 + :caption: OpenTelemetry Generative AI Instrumentations + :name: Generative AI Instrumentations + :glob: + + instrumentation-genai/** + .. toctree:: :maxdepth: 2 :caption: OpenTelemetry Propagators diff --git a/docs/instrumentation-genai/openai.rst b/docs/instrumentation-genai/openai.rst new file mode 100644 index 0000000000..9e7ff9e461 --- /dev/null +++ b/docs/instrumentation-genai/openai.rst @@ -0,0 +1,7 @@ +OpenTelemetry Python - OpenAI Instrumentation +=========================================== + +.. automodule:: opentelemetry.instrumentation.openai_v2 + :members: + :undoc-members: + :show-inheritance: \ No newline at end of file diff --git a/instrumentation-genai/opentelemetry-instrumentation-openai-v2/README.rst b/instrumentation-genai/opentelemetry-instrumentation-openai-v2/README.rst index 85817896ff..4e27aa3215 100644 --- a/instrumentation-genai/opentelemetry-instrumentation-openai-v2/README.rst +++ b/instrumentation-genai/opentelemetry-instrumentation-openai-v2/README.rst @@ -17,6 +17,53 @@ Installation pip install opentelemetry-instrumentation-openai-v2 +Usage +----- + +Instrumenting all clients +************************* + +When using the instrumentor, all clients will automatically trace OpenAI chat completion operations +and capture prompts and completions as events. + +Make sure to configure OpenTelemetry tracing, logging, and events to capture all telemetry emitted by the instrumentation. + +.. code-block:: python + + from opentelemetry.instrumentation.openai_v2 import OpenAIInstrumentor + + OpenAIInstrumentor().instrument() + + client = OpenAI() + response = client.chat.completions.create( + model="gpt-4o-mini", + messages=[ + {"role": "user", "content": "Write a short poem on open telemetry."}, + ], + ) + +Enabling message content +************************* + +Message content such as the contents of the prompt, completion, function arguments and return values +are not captured by default. To enable message content, set the environment variable +`OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT` to `true`. + +Uninstrument +************ + +To uninstrument clients, call the uninstrument method: + +.. code-block:: python + + from opentelemetry.instrumentation.openai_v2 import OpenAIInstrumentor + + OpenAIInstrumentor().instrument() + # ... + + # Uninstrument all clients + OpenAIInstrumentor().uninstrument() + References ----------