@@ -19,8 +19,60 @@ package to your requirements.
19
19
20
20
pip install opentelemetry-instrumentation-openai-v2
21
21
22
- If you don't have an OpenAI application, yet, try our `example <example >`_
23
- which only needs a valid OpenAI API key.
22
+ If you don't have an OpenAI application, yet, try our `examples <examples >`_
23
+ which only need a valid OpenAI API key.
24
+
25
+ Check out `zero-code example <examples/zero-code >`_ for a quick start.
26
+
27
+ Usage
28
+ -----
29
+
30
+ This section describes how to set up OpenAI instrumentation if you're setting OpenTelemetry up manually.
31
+ Check out the `manual example <examples/manual >`_ for more details.
32
+
33
+ Instrumenting all clients
34
+ *************************
35
+
36
+ When using the instrumentor, all clients will automatically trace OpenAI chat completion operations.
37
+ You can also optionally capture prompts and completions as log events.
38
+
39
+ Make sure to configure OpenTelemetry tracing, logging, and events to capture all telemetry emitted by the instrumentation.
40
+
41
+ .. code-block :: python
42
+
43
+ from opentelemetry.instrumentation.openai_v2 import OpenAIInstrumentor
44
+
45
+ OpenAIInstrumentor().instrument()
46
+
47
+ client = OpenAI()
48
+ response = client.chat.completions.create(
49
+ model = " gpt-4o-mini" ,
50
+ messages = [
51
+ {" role" : " user" , " content" : " Write a short poem on open telemetry." },
52
+ ],
53
+ )
54
+
55
+ Enabling message content
56
+ *************************
57
+
58
+ Message content such as the contents of the prompt, completion, function arguments and return values
59
+ are not captured by default. To capture message content as log events, set the environment variable
60
+ `OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT ` to `true `.
61
+
62
+ Uninstrument
63
+ ************
64
+
65
+ To uninstrument clients, call the uninstrument method:
66
+
67
+ .. code-block :: python
68
+
69
+ from opentelemetry.instrumentation.openai_v2 import OpenAIInstrumentor
70
+
71
+ OpenAIInstrumentor().instrument()
72
+ # ...
73
+
74
+ # Uninstrument all clients
75
+ OpenAIInstrumentor().uninstrument()
24
76
25
77
References
26
78
----------
0 commit comments