File tree Expand file tree Collapse file tree 3 files changed +21
-7
lines changed
Expand file tree Collapse file tree 3 files changed +21
-7
lines changed Original file line number Diff line number Diff line change @@ -78,13 +78,14 @@ def wrapper(*args: Any, **kwargs: Any) -> Any:
7878 logging .exception ("Failed to initialize Sentry or start transaction" )
7979
8080 # Initialize and track with Elastic APM if enabled
81- elastic_client = None
8281 if config .ELASTIC_APM .IS_ENABLED :
8382 try :
8483 import elasticapm
8584
8685 # Initialize Elastic APM client with config
87- elastic_client = elasticapm .Client (config .ELASTIC_APM .model_dump ())
86+ elastic_client = elasticapm .get_client ()
87+ if not elastic_client :
88+ elastic_client = elasticapm .Client (config .ELASTIC_APM .model_dump ())
8889 elastic_client .begin_transaction (transaction_type = "function" )
8990 except ImportError :
9091 logging .debug ("elasticapm is not installed, skipping Elastic APM transaction capture." )
Original file line number Diff line number Diff line change @@ -85,12 +85,12 @@ def intercept(
8585 logging .exception ("Failed to create Sentry transaction for gRPC server call" )
8686
8787 # Handle Elastic APM if enabled
88- elastic_client = None
8988 if config .ELASTIC_APM .IS_ENABLED :
9089 try :
9190 # Get the Elastic APM client
92- elastic_client = elasticapm .Client (config .ELASTIC_APM .model_dump ())
93-
91+ elastic_client = elasticapm .get_client ()
92+ if not elastic_client :
93+ elastic_client = elasticapm .Client (config .ELASTIC_APM .model_dump ())
9494 # Check if a trace parent header is present in the metadata
9595 if parent := elasticapm .trace_parent_from_headers (metadata_dict ):
9696 # Start a transaction linked to the distributed trace
@@ -203,11 +203,12 @@ async def intercept(
203203 logging .exception ("Failed to create Sentry transaction for async gRPC server call" )
204204
205205 # Handle Elastic APM if enabled
206- elastic_client = None
207206 if config .ELASTIC_APM .IS_ENABLED :
208207 try :
209208 # Get the Elastic APM client
210- elastic_client = elasticapm .Client (config .ELASTIC_APM .model_dump ())
209+ elastic_client = elasticapm .get_client ()
210+ if not elastic_client :
211+ elastic_client = elasticapm .Client (config .ELASTIC_APM .model_dump ())
211212
212213 # Check if a trace parent header is present in the metadata
213214 if parent := elasticapm .trace_parent_from_headers (metadata_dict ):
Original file line number Diff line number Diff line change 22
33All notable changes to ArchiPy are documented in this changelog, organized by version.
44
5+ ## [ 3.13.9] - 2025-10-15
6+
7+ ### Improved
8+
9+ #### Elastic APM Client Initialization
10+
11+ - ** Enhanced Client Reuse** - Improved Elastic APM client initialization to prevent duplicate client creation
12+ - Updated tracing decorators to use ` elasticapm.get_client() ` before creating new clients
13+ - Applied same pattern to gRPC server interceptors (both sync and async)
14+ - Prevents potential memory leaks and improves performance by reusing existing clients
15+ - Maintains backward compatibility while optimizing resource usage
16+
517## [ 3.13.8] - 2025-10-15
618
719### Changed
You can’t perform that action at this time.
0 commit comments