Skip to content

Commit 6609cf2

Browse files
committed
feat: deprecate register_otel_exporter function
1 parent afa7010 commit 6609cf2

File tree

3 files changed

+81
-2
lines changed

3 files changed

+81
-2
lines changed

examples/configs/tracing/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,36 @@ config = RailsConfig.from_content(
337337
)
338338
```
339339

340+
### Deprecated Features
341+
342+
#### register_otel_exporter Function
343+
344+
The `register_otel_exporter` function is deprecated and will be removed in version 0.16.0:
345+
346+
```python
347+
# DEPRECATED - will be removed in 0.16.0
348+
from nemoguardrails.tracing.adapters.opentelemetry import register_otel_exporter
349+
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
350+
351+
register_otel_exporter("my-otlp", OTLPSpanExporter)
352+
```
353+
354+
Instead, configure exporters directly in your application:
355+
356+
```python
357+
from opentelemetry import trace
358+
from opentelemetry.sdk.trace import TracerProvider
359+
from opentelemetry.sdk.trace.export import BatchSpanProcessor
360+
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
361+
362+
tracer_provider = TracerProvider()
363+
trace.set_tracer_provider(tracer_provider)
364+
365+
otlp_exporter = OTLPSpanExporter(endpoint="http://localhost:4318")
366+
span_processor = BatchSpanProcessor(otlp_exporter)
367+
tracer_provider.add_span_processor(span_processor)
368+
```
369+
340370
### Why the Change?
341371

342372
This change follows OpenTelemetry best practices:

nemoguardrails/tracing/adapters/opentelemetry.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555

5656
import warnings
5757
from importlib.metadata import version
58-
from typing import TYPE_CHECKING
58+
from typing import TYPE_CHECKING, Optional, Type
5959

6060
if TYPE_CHECKING:
6161
from nemoguardrails.tracing import InteractionLog
@@ -71,6 +71,34 @@
7171

7272
from nemoguardrails.tracing.adapters.base import InteractionLogAdapter
7373

74+
# DEPRECATED: global dictionary to store registered exporters
75+
# will be removed in v0.16.0
76+
_exporter_name_cls_map: dict[str, Type] = {}
77+
78+
79+
def register_otel_exporter(name: str, exporter_cls: Type):
80+
"""Register a new exporter.
81+
82+
Args:
83+
name: The name to register the exporter under.
84+
exporter_cls: The exporter class to register.
85+
86+
Deprecated:
87+
This function is deprecated and will be removed in version 0.16.0.
88+
Please configure OpenTelemetry exporters directly in your application code.
89+
See the migration guide at:
90+
https://github.com/NVIDIA/NeMo-Guardrails/blob/main/examples/configs/tracing/README.md#migration-guide
91+
"""
92+
warnings.warn(
93+
"register_otel_exporter is deprecated and will be removed in version 0.16.0. "
94+
"Please configure OpenTelemetry exporters directly in your application code. "
95+
"See the migration guide at: "
96+
"https://github.com/NVIDIA/NeMo-Guardrails/blob/develop/examples/configs/tracing/README.md#migration-guide",
97+
DeprecationWarning,
98+
stacklevel=2,
99+
)
100+
_exporter_name_cls_map[name] = exporter_cls
101+
74102

75103
class OpenTelemetryAdapter(InteractionLogAdapter):
76104
"""

tests/test_tracing_adapters_opentelemetry.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,6 @@ def test_no_op_tracer_provider_warning(self):
332332

333333
def test_no_warnings_with_proper_configuration(self):
334334
"""Test that no warnings are issued when properly configured."""
335-
336335
with warnings.catch_warnings(record=True) as w:
337336
warnings.simplefilter("always")
338337

@@ -341,3 +340,25 @@ def test_no_warnings_with_proper_configuration(self):
341340

342341
# no warnings is issued
343342
self.assertEqual(len(w), 0)
343+
344+
def test_register_otel_exporter_deprecation(self):
345+
"""Test that register_otel_exporter shows deprecation warning."""
346+
from nemoguardrails.tracing.adapters.opentelemetry import register_otel_exporter
347+
348+
with warnings.catch_warnings(record=True) as w:
349+
warnings.simplefilter("always")
350+
351+
mock_exporter_cls = MagicMock()
352+
353+
register_otel_exporter("test-exporter", mock_exporter_cls)
354+
355+
self.assertEqual(len(w), 1)
356+
self.assertTrue(issubclass(w[0].category, DeprecationWarning))
357+
self.assertIn("register_otel_exporter is deprecated", str(w[0].message))
358+
self.assertIn("0.16.0", str(w[0].message))
359+
360+
from nemoguardrails.tracing.adapters.opentelemetry import (
361+
_exporter_name_cls_map,
362+
)
363+
364+
self.assertEqual(_exporter_name_cls_map["test-exporter"], mock_exporter_cls)

0 commit comments

Comments
 (0)