Skip to content

Commit dfbec80

Browse files
author
Liudmila Molkova
committed
Add openai docs config and improve readme
1 parent 4606cf2 commit dfbec80

File tree

4 files changed

+72
-2
lines changed

4 files changed

+72
-2
lines changed

docs/conf.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@
4040
if isdir(join(instr, f))
4141
]
4242

43+
instr_genai = "../instrumentation-genai"
44+
instr_genai_dirs = [
45+
os.path.abspath("/".join(["../instrumentation-genai", f, "src"]))
46+
for f in listdir(instr)
47+
if isdir(join(instr, f))
48+
]
49+
4350
prop = "../propagator"
4451
prop_dirs = [
4552
os.path.abspath("/".join([prop, f, "src"]))
@@ -60,7 +67,7 @@
6067
for f in listdir(resource)
6168
if isdir(join(resource, f))
6269
]
63-
sys.path[:0] = exp_dirs + instr_dirs + sdk_ext_dirs + prop_dirs + resource_dirs
70+
sys.path[:0] = exp_dirs + instr_dirs + instr_genai_dirs + sdk_ext_dirs + prop_dirs + resource_dirs
6471

6572
# -- Project information -----------------------------------------------------
6673

docs/index.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ installed separately via pip:
2424
pip install opentelemetry-instrumentation-{instrumentation}
2525
pip install opentelemetry-sdk-extension-{sdk-extension}
2626
27-
A complete list of packages can be found at the
27+
A complete list of packages can be found at the
2828
`Contrib repo instrumentation <https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation>`_
2929
and `Contrib repo exporter <https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/exporter>`_ directories.
3030

@@ -50,6 +50,7 @@ install <https://pip.pypa.io/en/stable/reference/pip_install/#editable-installs>
5050
cd opentelemetry-python-contrib
5151
pip install -e ./instrumentation/opentelemetry-instrumentation-flask
5252
pip install -e ./instrumentation/opentelemetry-instrumentation-botocore
53+
pip install -e ./instrumentation-genai/opentelemetry-instrumentation-openai-v2
5354
pip install -e ./sdk-extension/opentelemetry-sdk-extension-aws
5455
pip install -e ./resource/opentelemetry-resource-detector-container
5556
@@ -62,6 +63,14 @@ install <https://pip.pypa.io/en/stable/reference/pip_install/#editable-installs>
6263

6364
instrumentation/**
6465

66+
.. toctree::
67+
:maxdepth: 2
68+
:caption: OpenTelemetry Generative AI Instrumentations
69+
:name: Generative AI Instrumentations
70+
:glob:
71+
72+
instrumentation-genai/**
73+
6574
.. toctree::
6675
:maxdepth: 2
6776
:caption: OpenTelemetry Propagators
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
OpenTelemetry Python - OpenAI Instrumentation
2+
===========================================
3+
4+
.. automodule:: opentelemetry.instrumentation.openai_v2
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:

instrumentation-genai/opentelemetry-instrumentation-openai-v2/README.rst

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,53 @@ Installation
1717

1818
pip install opentelemetry-instrumentation-openai-v2
1919

20+
Usage
21+
-----
22+
23+
Instrumenting all clients
24+
*************************
25+
26+
When using the instrumentor, all clients will automatically trace OpenAI chat completion operations
27+
and capture prompts and completions as events.
28+
29+
Make sure to configure OpenTelemetry tracing, logging, and events to capture all telemetry emitted by the instrumentation.
30+
31+
.. code-block:: python
32+
33+
from opentelemetry.instrumentation.openai_v2 import OpenAIInstrumentor
34+
35+
OpenAIInstrumentor().instrument()
36+
37+
client = OpenAI()
38+
response = client.chat.completions.create(
39+
model="gpt-4o-mini",
40+
messages=[
41+
{"role": "user", "content": "Write a short poem on open telemetry."},
42+
],
43+
)
44+
45+
Enabling message content
46+
*************************
47+
48+
Message content such as the contents of the prompt, completion, function arguments and return values
49+
are not captured by default. To enable message content, set the environment variable
50+
`OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT` to `true`.
51+
52+
Uninstrument
53+
************
54+
55+
To uninstrument clients, call the uninstrument method:
56+
57+
.. code-block:: python
58+
59+
from opentelemetry.instrumentation.openai_v2 import OpenAIInstrumentor
60+
61+
OpenAIInstrumentor().instrument()
62+
# ...
63+
64+
# Uninstrument all clients
65+
OpenAIInstrumentor().uninstrument()
66+
2067
2168
References
2269
----------

0 commit comments

Comments
 (0)