Skip to content

Commit c7018ee

Browse files
author
Alisson Claudino
committed
fix: review suggestions, renaming and except guard
1 parent 0f40947 commit c7018ee

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

Diff for: elasticsearch/_otel.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646

4747
class OpenTelemetry:
48-
current_context: dict[str, str] = {}
48+
context_carrier: dict[str, str] = {}
4949

5050
def __init__(
5151
self,
@@ -80,8 +80,7 @@ def span(
8080

8181
span_name = endpoint_id or method
8282
with self.tracer.start_as_current_span(span_name) as otel_span:
83-
self.current_context = {}
84-
TraceContextTextMapPropagator().inject(self.current_context)
83+
TraceContextTextMapPropagator().inject(self.context_carrier)
8584
otel_span.set_attribute("http.request.method", method)
8685
otel_span.set_attribute("db.system", "elasticsearch")
8786
if endpoint_id is not None:
@@ -98,12 +97,13 @@ def span(
9897
@contextlib.contextmanager
9998
def recover_parent_context(self) -> Generator[None, None, None]:
10099
token = None
101-
if self.current_context:
100+
if self.context_carrier:
102101
otel_parent_ctx = TraceContextTextMapPropagator().extract(
103-
carrier=self.current_context
102+
carrier=self.context_carrier
104103
)
105104
token = otel_context.attach(otel_parent_ctx)
106-
yield
107-
108-
if token:
109-
otel_context.detach(token)
105+
try:
106+
yield
107+
finally:
108+
if token:
109+
otel_context.detach(token)

0 commit comments

Comments
 (0)