Skip to content

Commit d8997f0

Browse files
committed
Remove buckets example, add to main README
1 parent 344c893 commit d8997f0

File tree

5 files changed

+42
-149
lines changed

5 files changed

+42
-149
lines changed

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,48 @@ To uninstrument clients, call the uninstrument method:
7575
# Uninstrument all clients
7676
OpenAIInstrumentor().uninstrument()
7777
78+
Bucket Boundaries
79+
-----------------
80+
81+
This section describes the explicit bucket boundaries for metrics such as token usage and operation duration, and guides users to create Views to implement them according to the semantic conventions.
82+
83+
The bucket boundaries are defined as follows:
84+
85+
- For `gen_ai.client.token.usage`: [1, 4, 16, 64, 256, 1024, 4096, 16384, 65536, 262144, 1048576, 4194304, 16777216, 67108864]
86+
- For `gen_ai.client.operation.duration`: [0.01, 0.02, 0.04, 0.08, 0.16, 0.32, 0.64, 1.28, 2.56, 5.12, 10.24, 20.48, 40.96, 81.92]
87+
88+
To implement these bucket boundaries, you can create Views in your OpenTelemetry SDK setup. Here is an example:
89+
90+
.. code-block:: python
91+
92+
from opentelemetry.sdk.metrics import MeterProvider, View
93+
from opentelemetry.sdk.metrics.export import PeriodicExportingMetricReader
94+
from opentelemetry.exporter.otlp.proto.grpc.metric_exporter import OTLPMetricExporter
95+
from opentelemetry.sdk.metrics.aggregation import ExplicitBucketHistogramAggregation
96+
97+
views = [
98+
View(
99+
instrument_name="gen_ai.client.token.usage",
100+
aggregation=ExplicitBucketHistogramAggregation([1, 4, 16, 64, 256, 1024, 4096, 16384, 65536, 262144, 1048576, 4194304, 16777216, 67108864]),
101+
),
102+
View(
103+
instrument_name="gen_ai.client.operation.duration",
104+
aggregation=ExplicitBucketHistogramAggregation([0.01, 0.02, 0.04, 0.08, 0.16, 0.32, 0.64, 1.28, 2.56, 5.12, 10.24, 20.48, 40.96, 81.92]),
105+
),
106+
]
107+
108+
metric_exporter = OTLPMetricExporter(endpoint="http://localhost:4317")
109+
metric_reader = PeriodicExportingMetricReader(metric_exporter)
110+
provider = MeterProvider(
111+
metric_readers=[metric_reader],
112+
views=views
113+
)
114+
115+
from opentelemetry.sdk.metrics import set_meter_provider
116+
set_meter_provider(provider)
117+
118+
For more details, refer to the `OpenTelemetry GenAI Metrics documentation <https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-metrics/>`_.
119+
78120
References
79121
----------
80122
* `OpenTelemetry OpenAI Instrumentation <https://opentelemetry-python-contrib.readthedocs.io/en/latest/instrumentation/openai/openai.html>`_

instrumentation-genai/opentelemetry-instrumentation-openai-v2/examples/buckets/.env

Lines changed: 0 additions & 14 deletions
This file was deleted.

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

Lines changed: 0 additions & 38 deletions
This file was deleted.

instrumentation-genai/opentelemetry-instrumentation-openai-v2/examples/buckets/main.py

Lines changed: 0 additions & 92 deletions
This file was deleted.

instrumentation-genai/opentelemetry-instrumentation-openai-v2/examples/buckets/requirements.txt

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)