@@ -87,6 +87,25 @@ def response_hook(span, request, response):
87
87
import urllib3 .connectionpool
88
88
import wrapt
89
89
90
+ from opentelemetry .instrumentation ._semconv import (
91
+ _client_duration_attrs_new ,
92
+ _client_duration_attrs_old ,
93
+ _filter_semconv_duration_attrs ,
94
+ _get_schema_url ,
95
+ _HTTPStabilityMode ,
96
+ _OpenTelemetrySemanticConventionStability ,
97
+ _OpenTelemetryStabilitySignalType ,
98
+ _report_new ,
99
+ _report_old ,
100
+ _set_http_host ,
101
+ _set_http_method ,
102
+ _set_http_net_peer_name_client ,
103
+ _set_http_network_protocol_version ,
104
+ _set_http_peer_port_client ,
105
+ _set_http_scheme ,
106
+ _set_http_status_code ,
107
+ _set_http_url ,
108
+ )
90
109
from opentelemetry .instrumentation .instrumentor import BaseInstrumentor
91
110
from opentelemetry .instrumentation .urllib3 .package import _instruments
92
111
from opentelemetry .instrumentation .urllib3 .version import __version__
@@ -98,14 +117,23 @@ def response_hook(span, request, response):
98
117
)
99
118
from opentelemetry .metrics import Histogram , get_meter
100
119
from opentelemetry .propagate import inject
120
+ from opentelemetry .semconv .attributes .error_attributes import ERROR_TYPE
121
+ from opentelemetry .semconv .attributes .network_attributes import (
122
+ NETWORK_PEER_ADDRESS ,
123
+ NETWORK_PEER_PORT ,
124
+ )
101
125
from opentelemetry .semconv .metrics import MetricInstruments
126
+ from opentelemetry .semconv .metrics .http_metrics import (
127
+ HTTP_CLIENT_REQUEST_DURATION ,
128
+ )
102
129
from opentelemetry .semconv .trace import SpanAttributes
103
130
from opentelemetry .trace import Span , SpanKind , Tracer , get_tracer
104
131
from opentelemetry .trace .status import Status
105
132
from opentelemetry .util .http import (
106
133
ExcludeList ,
107
134
get_excluded_urls ,
108
135
parse_excluded_urls ,
136
+ sanitize_method ,
109
137
)
110
138
from opentelemetry .util .http .httplib import set_ip_on_next_http_connection
111
139
@@ -158,12 +186,18 @@ def _instrument(self, **kwargs):
158
186
``excluded_urls``: A string containing a comma-delimited
159
187
list of regexes used to exclude URLs from tracking
160
188
"""
189
+ # initialize semantic conventions opt-in if needed
190
+ _OpenTelemetrySemanticConventionStability ._initialize ()
191
+ sem_conv_opt_in_mode = _OpenTelemetrySemanticConventionStability ._get_opentelemetry_stability_opt_in_mode (
192
+ _OpenTelemetryStabilitySignalType .HTTP ,
193
+ )
194
+ schema_url = _get_schema_url (sem_conv_opt_in_mode )
161
195
tracer_provider = kwargs .get ("tracer_provider" )
162
196
tracer = get_tracer (
163
197
__name__ ,
164
198
__version__ ,
165
199
tracer_provider ,
166
- schema_url = "https://opentelemetry.io/schemas/1.11.0" ,
200
+ schema_url = schema_url ,
167
201
)
168
202
169
203
excluded_urls = kwargs .get ("excluded_urls" )
@@ -173,7 +207,7 @@ def _instrument(self, **kwargs):
173
207
__name__ ,
174
208
__version__ ,
175
209
meter_provider ,
176
- schema_url = "https://opentelemetry.io/schemas/1.11.0" ,
210
+ schema_url = schema_url ,
177
211
)
178
212
179
213
duration_histogram = meter .create_histogram (
@@ -205,6 +239,7 @@ def _instrument(self, **kwargs):
205
239
if excluded_urls is None
206
240
else parse_excluded_urls (excluded_urls )
207
241
),
242
+ sem_conv_opt_in_mode = sem_conv_opt_in_mode ,
208
243
)
209
244
210
245
def _uninstrument (self , ** kwargs ):
@@ -220,6 +255,7 @@ def _instrument(
220
255
response_hook : _ResponseHookT = None ,
221
256
url_filter : _UrlFilterT = None ,
222
257
excluded_urls : ExcludeList = None ,
258
+ sem_conv_opt_in_mode : _HTTPStabilityMode = _HTTPStabilityMode .DEFAULT ,
223
259
):
224
260
def instrumented_urlopen (wrapped , instance , args , kwargs ):
225
261
if not is_http_instrumentation_enabled ():
@@ -233,7 +269,7 @@ def instrumented_urlopen(wrapped, instance, args, kwargs):
233
269
headers = _prepare_headers (kwargs )
234
270
body = _get_url_open_arg ("body" , args , kwargs )
235
271
236
- span_name = method .strip ()
272
+ span_name = sanitize_method ( method .strip () )
237
273
span_attributes = {
238
274
SpanAttributes .HTTP_METHOD : method ,
239
275
SpanAttributes .HTTP_URL : url ,
@@ -282,7 +318,9 @@ def instrumented_urlopen(wrapped, instance, args, kwargs):
282
318
)
283
319
284
320
285
- def _get_url_open_arg (name : str , args : typing .List , kwargs : typing .Mapping ):
321
+ def _get_url_open_arg (
322
+ name : str , args : typing .List , kwargs : typing .Mapping
323
+ ) -> str :
286
324
arg_idx = _URL_OPEN_ARG_TO_INDEX_MAPPING .get (name )
287
325
if arg_idx is not None :
288
326
try :
0 commit comments