|
5 | 5 | import os |
6 | 6 | import random |
7 | 7 | import uuid |
| 8 | +from collections.abc import Callable |
8 | 9 | from dataclasses import asdict, is_dataclass |
9 | 10 | from datetime import datetime, timezone |
10 | 11 | from enum import Enum |
11 | 12 | from os import environ as env |
12 | | -from typing import Any, Callable, Dict, Optional |
| 13 | +from typing import Any, Dict, Mapping, Optional |
13 | 14 | from zoneinfo import ZoneInfo |
14 | 15 |
|
15 | 16 | from opentelemetry.sdk.trace import ReadableSpan |
|
20 | 21 |
|
21 | 22 |
|
22 | 23 | def get_supported_params( |
23 | | - tracer_impl: Callable, params: Dict[str, Any] |
| 24 | + tracer_impl: Callable[..., Any], |
| 25 | + params: Mapping[str, Any], |
24 | 26 | ) -> Dict[str, Any]: |
25 | | - """Extract the parameters supported by the tracer implementation. |
26 | | -
|
27 | | - Args: |
28 | | - tracer_impl: The tracer implementation function or callable |
29 | | - params: Dictionary of parameters to check |
30 | | -
|
31 | | - Returns: |
32 | | - Dictionary containing only parameters supported by the tracer implementation |
33 | | - """ |
34 | | - supported_params = {} |
35 | | - if hasattr(tracer_impl, "__code__"): |
36 | | - # For regular functions |
37 | | - impl_signature = inspect.signature(tracer_impl) |
38 | | - for param_name, param_value in params.items(): |
39 | | - if param_name in impl_signature.parameters and param_value is not None: |
40 | | - supported_params[param_name] = param_value |
41 | | - elif callable(tracer_impl): |
42 | | - # For callable objects |
43 | | - impl_signature = inspect.signature(tracer_impl.__call__) |
44 | | - for param_name, param_value in params.items(): |
45 | | - if param_name in impl_signature.parameters and param_value is not None: |
46 | | - supported_params[param_name] = param_value |
47 | | - else: |
| 27 | + """Extract the parameters supported by the tracer implementation.""" |
| 28 | + try: |
| 29 | + sig = inspect.signature(tracer_impl) |
| 30 | + except (TypeError, ValueError): |
48 | 31 | # If we can't inspect, pass all parameters and let the function handle it |
49 | | - supported_params = params |
| 32 | + return dict(params) |
50 | 33 |
|
51 | | - return supported_params |
| 34 | + supported: Dict[str, Any] = {} |
| 35 | + for name, value in params.items(): |
| 36 | + if value is not None and name in sig.parameters: |
| 37 | + supported[name] = value |
| 38 | + return supported |
52 | 39 |
|
53 | 40 |
|
54 | 41 | def _simple_serialize_defaults(obj): |
|
0 commit comments