|
10 | 10 | from dirty_equals import IsStr |
11 | 11 | from httpx import Request |
12 | 12 | from inline_snapshot import snapshot |
| 13 | +from opentelemetry.instrumentation._semconv import _OpenTelemetrySemanticConventionStability # type: ignore |
13 | 14 | from opentelemetry.instrumentation.httpx import RequestInfo, ResponseInfo |
14 | 15 | from opentelemetry.trace.span import Span |
15 | 16 |
|
@@ -98,6 +99,39 @@ def test_httpx_client_instrumentation(exporter: TestExporter): |
98 | 99 | ) |
99 | 100 |
|
100 | 101 |
|
| 102 | +def test_httpx_client_instrumentation_old_semconv(exporter: TestExporter): |
| 103 | + with mock.patch.dict('os.environ', {'OTEL_SEMCONV_STABILITY_OPT_IN': ''}): |
| 104 | + with httpx.Client(transport=create_transport()) as client: |
| 105 | + # Pick up the new value of OTEL_SEMCONV_STABILITY_OPT_IN |
| 106 | + _OpenTelemetrySemanticConventionStability._initialized = False # type: ignore |
| 107 | + |
| 108 | + logfire.instrument_httpx(client) |
| 109 | + client.get('https://example.org:8080/foo') |
| 110 | + |
| 111 | + # Now let other tests get the original value set in conftest.py |
| 112 | + _OpenTelemetrySemanticConventionStability._initialized = False # type: ignore |
| 113 | + |
| 114 | + assert exporter.exported_spans_as_dict() == snapshot( |
| 115 | + [ |
| 116 | + { |
| 117 | + 'name': 'GET', |
| 118 | + 'context': {'trace_id': 1, 'span_id': 1, 'is_remote': False}, |
| 119 | + 'parent': None, |
| 120 | + 'start_time': 1000000000, |
| 121 | + 'end_time': 2000000000, |
| 122 | + 'attributes': { |
| 123 | + 'http.method': 'GET', |
| 124 | + 'http.url': 'https://example.org:8080/foo', |
| 125 | + 'logfire.span_type': 'span', |
| 126 | + 'logfire.msg': 'GET example.org/foo', |
| 127 | + 'http.status_code': 200, |
| 128 | + 'http.target': '/foo', |
| 129 | + }, |
| 130 | + } |
| 131 | + ] |
| 132 | + ) |
| 133 | + |
| 134 | + |
101 | 135 | async def test_async_httpx_client_instrumentation(exporter: TestExporter): |
102 | 136 | with check_traceparent_header() as checker: |
103 | 137 | async with httpx.AsyncClient(transport=create_transport()) as client: |
|
0 commit comments