opentelemetry-instrumentation-aiohttp-client 0.46b0__py3-none-any.whl → 0.48b0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -90,19 +90,28 @@ import yarl
90
90
 
91
91
  from opentelemetry import context as context_api
92
92
  from opentelemetry import trace
93
+ from opentelemetry.instrumentation._semconv import (
94
+ _get_schema_url,
95
+ _HTTPStabilityMode,
96
+ _OpenTelemetrySemanticConventionStability,
97
+ _OpenTelemetryStabilitySignalType,
98
+ _report_new,
99
+ _set_http_method,
100
+ _set_http_url,
101
+ _set_status,
102
+ )
93
103
  from opentelemetry.instrumentation.aiohttp_client.package import _instruments
94
104
  from opentelemetry.instrumentation.aiohttp_client.version import __version__
95
105
  from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
96
106
  from opentelemetry.instrumentation.utils import (
97
- http_status_to_status_code,
98
107
  is_instrumentation_enabled,
99
108
  unwrap,
100
109
  )
101
110
  from opentelemetry.propagate import inject
102
- from opentelemetry.semconv.trace import SpanAttributes
111
+ from opentelemetry.semconv.attributes.error_attributes import ERROR_TYPE
103
112
  from opentelemetry.trace import Span, SpanKind, TracerProvider, get_tracer
104
113
  from opentelemetry.trace.status import Status, StatusCode
105
- from opentelemetry.util.http import remove_url_credentials
114
+ from opentelemetry.util.http import remove_url_credentials, sanitize_method
106
115
 
107
116
  _UrlFilterT = typing.Optional[typing.Callable[[yarl.URL], str]]
108
117
  _RequestHookT = typing.Optional[
@@ -122,11 +131,45 @@ _ResponseHookT = typing.Optional[
122
131
  ]
123
132
 
124
133
 
134
+ def _get_span_name(method: str) -> str:
135
+ method = sanitize_method(method.strip())
136
+ if method == "_OTHER":
137
+ method = "HTTP"
138
+ return method
139
+
140
+
141
+ def _set_http_status_code_attribute(
142
+ span,
143
+ status_code,
144
+ metric_attributes=None,
145
+ sem_conv_opt_in_mode=_HTTPStabilityMode.DEFAULT,
146
+ ):
147
+ status_code_str = str(status_code)
148
+ try:
149
+ status_code = int(status_code)
150
+ except ValueError:
151
+ status_code = -1
152
+ if metric_attributes is None:
153
+ metric_attributes = {}
154
+ # When we have durations we should set metrics only once
155
+ # Also the decision to include status code on a histogram should
156
+ # not be dependent on tracing decisions.
157
+ _set_status(
158
+ span,
159
+ metric_attributes,
160
+ status_code,
161
+ status_code_str,
162
+ server_span=False,
163
+ sem_conv_opt_in_mode=sem_conv_opt_in_mode,
164
+ )
165
+
166
+
125
167
  def create_trace_config(
126
168
  url_filter: _UrlFilterT = None,
127
169
  request_hook: _RequestHookT = None,
128
170
  response_hook: _ResponseHookT = None,
129
171
  tracer_provider: TracerProvider = None,
172
+ sem_conv_opt_in_mode: _HTTPStabilityMode = _HTTPStabilityMode.DEFAULT,
130
173
  ) -> aiohttp.TraceConfig:
131
174
  """Create an aiohttp-compatible trace configuration.
132
175
 
@@ -167,9 +210,12 @@ def create_trace_config(
167
210
  __name__,
168
211
  __version__,
169
212
  tracer_provider,
170
- schema_url="https://opentelemetry.io/schemas/1.11.0",
213
+ schema_url=_get_schema_url(sem_conv_opt_in_mode),
171
214
  )
172
215
 
216
+ # TODO: Use this when we have durations for aiohttp-client
217
+ metric_attributes = {}
218
+
173
219
  def _end_trace(trace_config_ctx: types.SimpleNamespace):
174
220
  context_api.detach(trace_config_ctx.token)
175
221
  trace_config_ctx.span.end()
@@ -183,18 +229,22 @@ def create_trace_config(
183
229
  trace_config_ctx.span = None
184
230
  return
185
231
 
186
- http_method = params.method.upper()
187
- request_span_name = f"{http_method}"
232
+ method = params.method
233
+ request_span_name = _get_span_name(method)
188
234
  request_url = (
189
235
  remove_url_credentials(trace_config_ctx.url_filter(params.url))
190
236
  if callable(trace_config_ctx.url_filter)
191
237
  else remove_url_credentials(str(params.url))
192
238
  )
193
239
 
194
- span_attributes = {
195
- SpanAttributes.HTTP_METHOD: http_method,
196
- SpanAttributes.HTTP_URL: request_url,
197
- }
240
+ span_attributes = {}
241
+ _set_http_method(
242
+ span_attributes,
243
+ method,
244
+ sanitize_method(method),
245
+ sem_conv_opt_in_mode,
246
+ )
247
+ _set_http_url(span_attributes, request_url, sem_conv_opt_in_mode)
198
248
 
199
249
  trace_config_ctx.span = trace_config_ctx.tracer.start_span(
200
250
  request_span_name, kind=SpanKind.CLIENT, attributes=span_attributes
@@ -219,14 +269,13 @@ def create_trace_config(
219
269
 
220
270
  if callable(response_hook):
221
271
  response_hook(trace_config_ctx.span, params)
272
+ _set_http_status_code_attribute(
273
+ trace_config_ctx.span,
274
+ params.response.status,
275
+ metric_attributes,
276
+ sem_conv_opt_in_mode,
277
+ )
222
278
 
223
- if trace_config_ctx.span.is_recording():
224
- trace_config_ctx.span.set_status(
225
- Status(http_status_to_status_code(int(params.response.status)))
226
- )
227
- trace_config_ctx.span.set_attribute(
228
- SpanAttributes.HTTP_STATUS_CODE, params.response.status
229
- )
230
279
  _end_trace(trace_config_ctx)
231
280
 
232
281
  async def on_request_exception(
@@ -238,7 +287,13 @@ def create_trace_config(
238
287
  return
239
288
 
240
289
  if trace_config_ctx.span.is_recording() and params.exception:
241
- trace_config_ctx.span.set_status(Status(StatusCode.ERROR))
290
+ exc_type = type(params.exception).__qualname__
291
+ if _report_new(sem_conv_opt_in_mode):
292
+ trace_config_ctx.span.set_attribute(ERROR_TYPE, exc_type)
293
+
294
+ trace_config_ctx.span.set_status(
295
+ Status(StatusCode.ERROR, exc_type)
296
+ )
242
297
  trace_config_ctx.span.record_exception(params.exception)
243
298
 
244
299
  if callable(response_hook):
@@ -271,6 +326,7 @@ def _instrument(
271
326
  trace_configs: typing.Optional[
272
327
  typing.Sequence[aiohttp.TraceConfig]
273
328
  ] = None,
329
+ sem_conv_opt_in_mode: _HTTPStabilityMode = _HTTPStabilityMode.DEFAULT,
274
330
  ):
275
331
  """Enables tracing of all ClientSessions
276
332
 
@@ -293,6 +349,7 @@ def _instrument(
293
349
  request_hook=request_hook,
294
350
  response_hook=response_hook,
295
351
  tracer_provider=tracer_provider,
352
+ sem_conv_opt_in_mode=sem_conv_opt_in_mode,
296
353
  )
297
354
  trace_config._is_instrumented_by_opentelemetry = True
298
355
  client_trace_configs.append(trace_config)
@@ -344,12 +401,17 @@ class AioHttpClientInstrumentor(BaseInstrumentor):
344
401
  ``trace_configs``: An optional list of aiohttp.TraceConfig items, allowing customize enrichment of spans
345
402
  based on aiohttp events (see specification: https://docs.aiohttp.org/en/stable/tracing_reference.html)
346
403
  """
404
+ _OpenTelemetrySemanticConventionStability._initialize()
405
+ _sem_conv_opt_in_mode = _OpenTelemetrySemanticConventionStability._get_opentelemetry_stability_opt_in_mode(
406
+ _OpenTelemetryStabilitySignalType.HTTP,
407
+ )
347
408
  _instrument(
348
409
  tracer_provider=kwargs.get("tracer_provider"),
349
410
  url_filter=kwargs.get("url_filter"),
350
411
  request_hook=kwargs.get("request_hook"),
351
412
  response_hook=kwargs.get("response_hook"),
352
413
  trace_configs=kwargs.get("trace_configs"),
414
+ sem_conv_opt_in_mode=_sem_conv_opt_in_mode,
353
415
  )
354
416
 
355
417
  def _uninstrument(self, **kwargs):
@@ -14,3 +14,7 @@
14
14
 
15
15
 
16
16
  _instruments = ("aiohttp ~= 3.0",)
17
+
18
+ _supports_metrics = False
19
+
20
+ _semconv_status = "migration"
@@ -12,4 +12,4 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
- __version__ = "0.46b0"
15
+ __version__ = "0.48b0"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: opentelemetry-instrumentation-aiohttp-client
3
- Version: 0.46b0
3
+ Version: 0.48b0
4
4
  Summary: OpenTelemetry aiohttp client instrumentation
5
5
  Project-URL: Homepage, https://github.com/open-telemetry/opentelemetry-python-contrib/tree/main/instrumentation/opentelemetry-instrumentation-aiohttp-client
6
6
  Author-email: OpenTelemetry Authors <cncf-opentelemetry-contributors@lists.cncf.io>
@@ -15,11 +15,12 @@ Classifier: Programming Language :: Python :: 3.8
15
15
  Classifier: Programming Language :: Python :: 3.9
16
16
  Classifier: Programming Language :: Python :: 3.10
17
17
  Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
18
19
  Requires-Python: >=3.8
19
20
  Requires-Dist: opentelemetry-api~=1.12
20
- Requires-Dist: opentelemetry-instrumentation==0.46b0
21
- Requires-Dist: opentelemetry-semantic-conventions==0.46b0
22
- Requires-Dist: opentelemetry-util-http==0.46b0
21
+ Requires-Dist: opentelemetry-instrumentation==0.48b0
22
+ Requires-Dist: opentelemetry-semantic-conventions==0.48b0
23
+ Requires-Dist: opentelemetry-util-http==0.48b0
23
24
  Requires-Dist: wrapt<2.0.0,>=1.0.0
24
25
  Provides-Extra: instruments
25
26
  Requires-Dist: aiohttp~=3.0; extra == 'instruments'
@@ -0,0 +1,8 @@
1
+ opentelemetry/instrumentation/aiohttp_client/__init__.py,sha256=l3EfkPyCLBDBd8bwC9jXuK4FYhzBZPV3j33gGKm5o4I,14294
2
+ opentelemetry/instrumentation/aiohttp_client/package.py,sha256=sNviXDOZG31-3USpt9VVWNqT8kAiIKaxtq-wi1k8WBM,681
3
+ opentelemetry/instrumentation/aiohttp_client/version.py,sha256=HRXiCQ2OeHywRgwG6rGky38ebvXDy-TQ6uBtMIN5wFM,610
4
+ opentelemetry_instrumentation_aiohttp_client-0.48b0.dist-info/METADATA,sha256=FTdIGLYelo9leHsESKKXpwUzRdNMYCAsG7GZ7jNb9lM,2078
5
+ opentelemetry_instrumentation_aiohttp_client-0.48b0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
6
+ opentelemetry_instrumentation_aiohttp_client-0.48b0.dist-info/entry_points.txt,sha256=RyZ5eVO-u3V_rwvLrhMM0ABs_WYZDqcagmMKwDPtmwE,117
7
+ opentelemetry_instrumentation_aiohttp_client-0.48b0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
8
+ opentelemetry_instrumentation_aiohttp_client-0.48b0.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.24.2
2
+ Generator: hatchling 1.25.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -1,8 +0,0 @@
1
- opentelemetry/instrumentation/aiohttp_client/__init__.py,sha256=ZFvlrUbyi-U1Im22G5OFDPskcefx4L64LPdC-CVY1HI,12373
2
- opentelemetry/instrumentation/aiohttp_client/package.py,sha256=p_Q78PKsyRJD-WRU8p_peiPrGxilvGbfeZce0IiMkII,623
3
- opentelemetry/instrumentation/aiohttp_client/version.py,sha256=rjIU3AqMQrZC8zvWWAfHmCitnFtz6L_9z35r5OH_Q6M,610
4
- opentelemetry_instrumentation_aiohttp_client-0.46b0.dist-info/METADATA,sha256=we-F63fZn_1ttKs-qrTNK2wnaot0yW1cV9taHcQ6M64,2027
5
- opentelemetry_instrumentation_aiohttp_client-0.46b0.dist-info/WHEEL,sha256=zEMcRr9Kr03x1ozGwg5v9NQBKn3kndp6LSoSlVg-jhU,87
6
- opentelemetry_instrumentation_aiohttp_client-0.46b0.dist-info/entry_points.txt,sha256=RyZ5eVO-u3V_rwvLrhMM0ABs_WYZDqcagmMKwDPtmwE,117
7
- opentelemetry_instrumentation_aiohttp_client-0.46b0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
8
- opentelemetry_instrumentation_aiohttp_client-0.46b0.dist-info/RECORD,,