warpzone-sdk 15.0.0.dev1__py3-none-any.whl → 15.0.0.dev3__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.
@@ -1,14 +1,34 @@
1
- import asyncio
1
+ import inspect
2
2
  from contextlib import contextmanager
3
3
  from typing import Callable
4
4
 
5
5
  import azure.functions as func
6
6
  from azure.monitor.opentelemetry import configure_azure_monitor
7
+ from opentelemetry import trace
7
8
 
8
9
  from warpzone.function.types import SingleArgumentCallable
9
10
  from warpzone.monitor import logs, traces
10
11
 
11
- configure_azure_monitor()
12
+ # Lazy initialization flag to ensure configure_azure_monitor is called only once
13
+ _monitor_configured = False
14
+
15
+
16
+ def _ensure_monitor_configured():
17
+ """Configure Azure Monitor lazily on first use to ensure proper trace context."""
18
+ global _monitor_configured
19
+ if not _monitor_configured:
20
+ configure_azure_monitor()
21
+
22
+ # Apply trace filtering to suppress all Azure SDK traces except Service Bus
23
+ tracer_provider = trace.get_tracer_provider()
24
+ if hasattr(tracer_provider, "_active_span_processor"):
25
+ # Wrap the existing span processor with our filter
26
+ original_processor = tracer_provider._active_span_processor
27
+ filtered_processor = traces.AzureSDKTraceFilter(original_processor)
28
+ tracer_provider._active_span_processor = filtered_processor
29
+
30
+ _monitor_configured = True
31
+
12
32
 
13
33
  SUBJECT_IDENTIFIER = "<Subject>"
14
34
 
@@ -45,16 +65,18 @@ def monitor(main: SingleArgumentCallable) -> Callable:
45
65
  """
46
66
 
47
67
  async def wrapper_async(arg, context: func.Context):
68
+ _ensure_monitor_configured()
48
69
  with run_in_trace_context(context):
49
70
  result = await main(arg)
50
71
  return result
51
72
 
52
73
  def wrapper(arg, context: func.Context):
74
+ _ensure_monitor_configured()
53
75
  with run_in_trace_context(context):
54
76
  result = main(arg)
55
77
  return result
56
78
 
57
- if asyncio.iscoroutinefunction(main):
79
+ if inspect.iscoroutinefunction(main):
58
80
  return wrapper_async
59
81
  else:
60
82
  return wrapper
@@ -2,11 +2,59 @@ from contextlib import contextmanager
2
2
 
3
3
  from azure.core.settings import settings
4
4
  from opentelemetry import context, trace
5
+ from opentelemetry.sdk.trace import ReadableSpan, SpanProcessor
5
6
  from opentelemetry.trace.propagation.tracecontext import TraceContextTextMapPropagator
6
7
 
7
8
  settings.tracing_implementation = "opentelemetry"
8
9
 
9
10
 
11
+ class AzureSDKTraceFilter(SpanProcessor):
12
+ """Custom SpanProcessor to filter out Azure SDK traces except Service Bus.
13
+
14
+ It drops spans from Azure SDK libraries except Service Bus messages,
15
+ preventing them from being exported to Azure Monitor.
16
+ """
17
+
18
+ def __init__(self, wrapped_processor: SpanProcessor):
19
+ """Initialize with the actual processor to wrap.
20
+
21
+ Args:
22
+ wrapped_processor: The underlying processor (e.g., BatchSpanProcessor)
23
+ """
24
+ self.wrapped_processor = wrapped_processor
25
+
26
+ def on_start(
27
+ self, span: ReadableSpan, parent_context: context.Context = None
28
+ ) -> None:
29
+ """Called when a span is started."""
30
+ self.wrapped_processor.on_start(span, parent_context)
31
+
32
+ def on_end(self, span: ReadableSpan) -> None:
33
+ """Called when a span is ended. Filter based on span attributes."""
34
+ # Check if service bus span - always allow
35
+ if "servicebus.message" in span.name.lower():
36
+ self.wrapped_processor.on_end(span)
37
+ return
38
+
39
+ # Check if this is an Azure SDK span we want to suppress
40
+ instrumentation_scope = span.instrumentation_scope
41
+ if instrumentation_scope and instrumentation_scope.name:
42
+ # Suppress spans from Azure SDK libraries
43
+ if instrumentation_scope.name.startswith("azure."):
44
+ return # Drop this span
45
+
46
+ # Pass through all other spans
47
+ self.wrapped_processor.on_end(span)
48
+
49
+ def shutdown(self) -> None:
50
+ """Shutdown the wrapped processor."""
51
+ self.wrapped_processor.shutdown()
52
+
53
+ def force_flush(self, timeout_millis: int = 30000) -> bool:
54
+ """Force flush the wrapped processor."""
55
+ return self.wrapped_processor.force_flush(timeout_millis)
56
+
57
+
10
58
  @contextmanager
11
59
  def set_trace_context(trace_parent: str, trace_state: str = ""):
12
60
  """Context manager for setting the trace context
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: warpzone-sdk
3
- Version: 15.0.0.dev1
3
+ Version: 15.0.0.dev3
4
4
  Summary: The main objective of this package is to centralize logic used to interact with Azure Functions, Azure Service Bus and Azure Table Storage
5
5
  Author: Team Enigma
6
6
  Author-email: enigma@energinet.dk
@@ -17,7 +17,7 @@ warpzone/function/__init__.py,sha256=rJOZBpWsUgjMc7YtXMJ1rLGm45KB1AhDJ_Y2ISiSISc
17
17
  warpzone/function/checks.py,sha256=B9YqThymf16ac_fVAYKilv20ru5v9nwXgHlbxYIaG98,1018
18
18
  warpzone/function/functionize.py,sha256=bSV0QvwKbD9Vo3a_8cc1rgV2rzTdMMvidinyXItBfvs,2128
19
19
  warpzone/function/integrations.py,sha256=sDt2BTx6a4mVc-33wTITP9XQVPustwj7rkX4urTyOqo,4018
20
- warpzone/function/monitor.py,sha256=-WnbllgphJs1JRn_UxkLDHALM2UlrtEwy4ORh8eJ-xI,1660
20
+ warpzone/function/monitor.py,sha256=gGWoxrOTaXofds8FJwPwGf58q0XV19Xwj9VRzhr0GM8,2594
21
21
  warpzone/function/process.py,sha256=nbUVywM8ChfUwuaqFisgaD98aNRgeZkK4g5sbtuBdRs,2339
22
22
  warpzone/function/processors/__init__.py,sha256=DhIdSWLBcIeSO8IJdxPqGIhgwwnkDN6_Xqwy93BCLeA,46
23
23
  warpzone/function/processors/dependencies.py,sha256=m17BwdKyQEvzCPxpQZpAW5l1uYRIHWmweDz3XJskmpA,1259
@@ -29,7 +29,7 @@ warpzone/healthchecks/__init__.py,sha256=9gc_Mt2szs8sDSwy0V4l3JZ6d9hX41xTpZCkDP2
29
29
  warpzone/healthchecks/model.py,sha256=mM7DnrirLbUpBPPfi82MUPP654D0eOR2_F65TmzsPD0,1187
30
30
  warpzone/monitor/__init__.py,sha256=ggI5fIUu-szgC44ICzuOmpYrIoVOKPbsMT3zza9ssD4,87
31
31
  warpzone/monitor/logs.py,sha256=V1A2ImqbPo4c-hDr2qWAZlpr2muyVar30eI9mF2_rzE,986
32
- warpzone/monitor/traces.py,sha256=SQckLC4LCEbgg79ZBnmYcm26IaxJfHDQ9GV7Huh2Uls,1393
32
+ warpzone/monitor/traces.py,sha256=PhhYeZlPc7EOSq9KVsHdKOwEIivDHCV-RwZnDNVL7ic,3244
33
33
  warpzone/servicebus/data/__init__.py,sha256=lnc0uiaGLF0qMi_rWhCpRSFvaj0CJEiMCAl6Yqn1ZiA,21
34
34
  warpzone/servicebus/data/client.py,sha256=zECS3JwedhYnDk8PntYgIYpBF_uu9YN38KzpPFK7CKs,6511
35
35
  warpzone/servicebus/events/__init__.py,sha256=lnc0uiaGLF0qMi_rWhCpRSFvaj0CJEiMCAl6Yqn1ZiA,21
@@ -52,6 +52,6 @@ warpzone/tools/copy.py,sha256=5fddotMZkXZO8avzUbGOhvs0cp8mce95pNpy0oPVjnQ,2596
52
52
  warpzone/transform/__init__.py,sha256=ruGa7tl-v4ndlWpULE1jSGU_a4_iRc3V6eyNr5xKP9E,27
53
53
  warpzone/transform/data.py,sha256=Abb8PcrgMbbNCJkkIUdtrTHdlY0OfXid387qw1nDpFY,2362
54
54
  warpzone/transform/schema.py,sha256=nbSQtDMvXkyqGKuwhuFCF0WsEDsaNyoPYpMKvbsKlv8,2423
55
- warpzone_sdk-15.0.0.dev1.dist-info/METADATA,sha256=U7Mz9332k6VsVXQitNaurDeed-oD4QBFyEmPaMWJexM,7398
56
- warpzone_sdk-15.0.0.dev1.dist-info/WHEEL,sha256=3ny-bZhpXrU6vSQ1UPG34FoxZBp3lVcvK0LkgUz6VLk,88
57
- warpzone_sdk-15.0.0.dev1.dist-info/RECORD,,
55
+ warpzone_sdk-15.0.0.dev3.dist-info/METADATA,sha256=SbdclS53SblY02qVWfnpicAHmSQJXPqKIfz_gAxtaRM,7398
56
+ warpzone_sdk-15.0.0.dev3.dist-info/WHEEL,sha256=3ny-bZhpXrU6vSQ1UPG34FoxZBp3lVcvK0LkgUz6VLk,88
57
+ warpzone_sdk-15.0.0.dev3.dist-info/RECORD,,