|
72 | 72 | import anthropic |
73 | 73 | import httpx |
74 | 74 | import openai |
| 75 | + import requests |
75 | 76 | from django.http import HttpRequest, HttpResponse |
76 | 77 | from fastapi import FastAPI |
77 | 78 | from flask.app import Flask |
|
84 | 85 | from .integrations.asgi import ASGIApp, ASGIInstrumentKwargs |
85 | 86 | from .integrations.asyncpg import AsyncPGInstrumentKwargs |
86 | 87 | from .integrations.aws_lambda import AwsLambdaInstrumentKwargs, LambdaHandler |
87 | | - from .integrations.celery import CeleryInstrumentKwargs |
88 | 88 | from .integrations.flask import FlaskInstrumentKwargs |
89 | 89 | from .integrations.httpx import AsyncClientKwargs, ClientKwargs, HTTPXInstrumentKwargs |
90 | 90 | from .integrations.mysql import MySQLConnection, MySQLInstrumentKwargs |
@@ -1224,17 +1224,26 @@ def instrument_httpx( |
1224 | 1224 | **kwargs, |
1225 | 1225 | ) |
1226 | 1226 |
|
1227 | | - def instrument_celery(self, **kwargs: Unpack[CeleryInstrumentKwargs]) -> None: |
| 1227 | + def instrument_celery(self, **kwargs: Any) -> None: |
1228 | 1228 | """Instrument `celery` so that spans are automatically created for each task. |
1229 | 1229 |
|
1230 | 1230 | Uses the |
1231 | 1231 | [OpenTelemetry Celery Instrumentation](https://opentelemetry-python-contrib.readthedocs.io/en/latest/instrumentation/celery/celery.html) |
1232 | 1232 | library. |
| 1233 | +
|
| 1234 | + Args: |
| 1235 | + **kwargs: Additional keyword arguments to pass to the OpenTelemetry `instrument` method, for future compatibility. |
1233 | 1236 | """ |
1234 | 1237 | from .integrations.celery import instrument_celery |
1235 | 1238 |
|
1236 | 1239 | self._warn_if_not_initialized_for_instrumentation() |
1237 | | - return instrument_celery(self, **kwargs) |
| 1240 | + return instrument_celery( |
| 1241 | + **{ |
| 1242 | + 'tracer_provider': self._config.get_tracer_provider(), |
| 1243 | + 'meter_provider': self._config.get_meter_provider(), |
| 1244 | + **kwargs, |
| 1245 | + }, |
| 1246 | + ) |
1238 | 1247 |
|
1239 | 1248 | def instrument_django( |
1240 | 1249 | self, |
@@ -1288,18 +1297,34 @@ def instrument_django( |
1288 | 1297 | **kwargs, |
1289 | 1298 | ) |
1290 | 1299 |
|
1291 | | - def instrument_requests(self, excluded_urls: str | None = None, **kwargs: Any) -> None: |
| 1300 | + def instrument_requests( |
| 1301 | + self, |
| 1302 | + excluded_urls: str | None = None, |
| 1303 | + request_hook: Callable[[Span, requests.PreparedRequest], None] | None = None, |
| 1304 | + response_hook: Callable[[Span, requests.PreparedRequest, requests.Response], None] | None = None, |
| 1305 | + **kwargs: Any, |
| 1306 | + ) -> None: |
1292 | 1307 | """Instrument the `requests` module so that spans are automatically created for each request. |
1293 | 1308 |
|
1294 | 1309 | Args: |
1295 | 1310 | excluded_urls: A string containing a comma-delimited list of regexes used to exclude URLs from tracking |
1296 | | - **kwargs: Additional keyword arguments to pass to the OpenTelemetry `instrument` methods, |
1297 | | - particularly `request_hook` and `response_hook`. |
| 1311 | + request_hook: A function called right after a span is created for a request. |
| 1312 | + response_hook: A function called right before a span is finished for the response. |
| 1313 | + **kwargs: Additional keyword arguments to pass to the OpenTelemetry `instrument` methods, for future compatibility. |
1298 | 1314 | """ |
1299 | 1315 | from .integrations.requests import instrument_requests |
1300 | 1316 |
|
1301 | 1317 | self._warn_if_not_initialized_for_instrumentation() |
1302 | | - return instrument_requests(self, excluded_urls=excluded_urls, **kwargs) |
| 1318 | + return instrument_requests( |
| 1319 | + excluded_urls=excluded_urls, |
| 1320 | + request_hook=request_hook, |
| 1321 | + response_hook=response_hook, |
| 1322 | + **{ |
| 1323 | + 'tracer_provider': self._config.get_tracer_provider(), |
| 1324 | + 'meter_provider': self._config.get_meter_provider(), |
| 1325 | + **kwargs, |
| 1326 | + }, |
| 1327 | + ) |
1303 | 1328 |
|
1304 | 1329 | def instrument_psycopg(self, conn_or_module: Any = None, **kwargs: Unpack[PsycopgInstrumentKwargs]) -> None: |
1305 | 1330 | """Instrument a `psycopg` connection or module so that spans are automatically created for each query. |
|
0 commit comments