nucliadb-telemetry 6.4.0.post4171__py3-none-any.whl → 6.4.0.post4184__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.

Potentially problematic release.


This version of nucliadb-telemetry might be problematic. Click here for more details.

@@ -72,7 +72,7 @@ def start_span_message_receiver(tracer: Tracer, msg: Msg):
72
72
  }
73
73
 
74
74
  # add some attributes from the metadata
75
- ctx = extract(msg.headers)
75
+ ctx = extract(msg.headers or {})
76
76
 
77
77
  span = tracer.start_as_current_span(
78
78
  name=f"Received from {msg.subject}",
@@ -98,6 +98,24 @@ def start_span_message_publisher(tracer: Tracer, subject: str):
98
98
  return span
99
99
 
100
100
 
101
+ async def _traced_callback(origin_cb: Callable[[Msg], Awaitable[None]], tracer: Tracer, msg: Msg):
102
+ with start_span_message_receiver(tracer, msg) as span:
103
+ try:
104
+ await origin_cb(msg)
105
+ except Exception as error:
106
+ set_span_exception(span, error)
107
+ raise error
108
+ finally:
109
+ msg_consume_time_histo.observe(
110
+ (datetime.now() - msg.metadata.timestamp).total_seconds(),
111
+ {
112
+ "stream": msg.metadata.stream,
113
+ "consumer": msg.metadata.consumer or "",
114
+ "acked": "yes" if msg._ackd else "no",
115
+ },
116
+ )
117
+
118
+
101
119
  class JetStreamContextTelemetry:
102
120
  def __init__(self, js: JetStreamContext, service_name: str, tracer_provider: TracerProvider):
103
121
  self.js = js
@@ -118,31 +136,11 @@ class JetStreamContextTelemetry:
118
136
  **kwargs,
119
137
  ):
120
138
  tracer = self.tracer_provider.get_tracer(f"{self.service_name}_js_subscriber")
121
-
122
- async def wrapper(origin_cb, tracer, msg: Msg):
123
- # Execute the callback without tracing
124
- if msg.headers is None:
125
- logger.debug("Message received without headers, skipping span")
126
- await origin_cb(msg)
127
- return
128
-
129
- with start_span_message_receiver(tracer, msg) as span:
130
- try:
131
- await origin_cb(msg)
132
- except Exception as error:
133
- set_span_exception(span, error)
134
- raise error
135
- finally:
136
- msg_consume_time_histo.observe(
137
- (datetime.now() - msg.metadata.timestamp).total_seconds(),
138
- {
139
- "stream": msg.metadata.stream,
140
- "consumer": msg.metadata.consumer or "",
141
- "acked": "yes" if msg._ackd else "no", # type: ignore
142
- },
143
- )
144
-
145
- wrapped_cb = partial(wrapper, cb, tracer)
139
+ wrapped_cb: Optional[Callable[[Msg], Awaitable[None]]]
140
+ if cb is not None:
141
+ wrapped_cb = partial(_traced_callback, cb, tracer)
142
+ else:
143
+ wrapped_cb = cb
146
144
  return await self.js.subscribe(subject, queue=queue, cb=wrapped_cb, **kwargs)
147
145
 
148
146
  async def publish(
@@ -154,8 +152,8 @@ class JetStreamContextTelemetry:
154
152
  ):
155
153
  tracer = self.tracer_provider.get_tracer(f"{self.service_name}_js_publisher")
156
154
  headers = {} if headers is None else headers
157
- inject(headers)
158
155
  with start_span_message_publisher(tracer, subject) as span:
156
+ inject(headers)
159
157
  try:
160
158
  result = await self.js.publish(subject, body, headers=headers, **kwargs)
161
159
  msg_sent_counter.inc({"subject": subject, "status": metrics.OK})
@@ -166,6 +164,10 @@ class JetStreamContextTelemetry:
166
164
 
167
165
  return result
168
166
 
167
+ async def trace_pull_subscriber_message(self, cb: Callable[[Msg], Awaitable[None]], msg: Msg):
168
+ tracer = self.tracer_provider.get_tracer(f"{self.service_name}_js_pull_subscriber")
169
+ await _traced_callback(cb, tracer, msg)
170
+
169
171
  # Just for convenience, to wrap all we use in the context of
170
172
  # telemetry-instrumented stuff using the JetStreamContextTelemetry class
171
173
 
@@ -259,9 +261,9 @@ class NatsClientTelemetry:
259
261
  ) -> None:
260
262
  tracer = self.tracer_provider.get_tracer(f"{self.service_name}_nc_publisher")
261
263
  headers = {} if headers is None else headers
262
- inject(headers)
263
264
 
264
265
  with start_span_message_publisher(tracer, subject) as span:
266
+ inject(headers)
265
267
  try:
266
268
  await self.nc.publish(subject, body, reply, headers)
267
269
  msg_sent_counter.inc({"subject": subject, "status": metrics.OK})
@@ -279,9 +281,9 @@ class NatsClientTelemetry:
279
281
  headers: Optional[Dict[str, Any]] = None,
280
282
  ) -> Msg:
281
283
  headers = {} if headers is None else headers
282
- inject(headers)
283
284
  tracer = self.tracer_provider.get_tracer(f"{self.service_name}_nc_request")
284
285
  with start_span_message_publisher(tracer, subject) as span:
286
+ inject(headers)
285
287
  try:
286
288
  result = await self.nc.request(subject, payload, timeout, old_style, headers)
287
289
  except Exception as error:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nucliadb_telemetry
3
- Version: 6.4.0.post4171
3
+ Version: 6.4.0.post4184
4
4
  Summary: NucliaDB Telemetry Library Python process
5
5
  Author-email: Nuclia <nucliadb@nuclia.com>
6
6
  License: AGPL
@@ -7,7 +7,7 @@ nucliadb_telemetry/grpc.py,sha256=cNJRJLr0aRedKr5V_ufGqeidnMlBouML3QbFKkugTqg,15
7
7
  nucliadb_telemetry/grpc_metrics.py,sha256=L2XMcJDxioNUYPX_IbKl_zvrG8uOFpF_a67c6yJq-Jw,5174
8
8
  nucliadb_telemetry/grpc_sentry.py,sha256=3eS_DVIX5MzvbJBkykf8JyZUf1b_b9w1KLhjoiW7oV0,2659
9
9
  nucliadb_telemetry/jaeger.py,sha256=HMQK8x_oaol5tCx3hCjaMG5Uzvsy_WWhKnD-FEZoYA4,7036
10
- nucliadb_telemetry/jetstream.py,sha256=w6CLN_oGmQT0FgfMmQdtrASsEw5mCk3KW8TwaWCEl-E,11971
10
+ nucliadb_telemetry/jetstream.py,sha256=hhlAv0sEottFjRp16vjwf2aWQqsoGVttVgwjzh1jNVs,12053
11
11
  nucliadb_telemetry/logs.py,sha256=ag1e7tKEoNFgB1FuAmyTxdIHtTFwOJlGxPl2s1bhUic,9311
12
12
  nucliadb_telemetry/metrics.py,sha256=euexqkmlZip6QFbMfvJW1fSuha96J4ZHnMWixeVJnAs,8652
13
13
  nucliadb_telemetry/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -30,7 +30,7 @@ nucliadb_telemetry/tests/grpc/helloworld_pb2.py,sha256=ht4dmi0pAy6qDrwcjkbtSf_hO
30
30
  nucliadb_telemetry/tests/grpc/helloworld_pb2.pyi,sha256=mBZCQE6z7riQw6fOegJgZ5lHmXqO23_zxL8iQMqSqms,1191
31
31
  nucliadb_telemetry/tests/grpc/helloworld_pb2_grpc.py,sha256=_jxUNxl4Fx-JztK9RO5R6osjNP2sVNVPAxLnmczEYOc,2677
32
32
  nucliadb_telemetry/tests/grpc/helloworld_pb2_grpc.pyi,sha256=Y6teCx-PhPU-rI6w5ItLBKaTb34FLpngPnuDVWtNve4,958
33
- nucliadb_telemetry-6.4.0.post4171.dist-info/METADATA,sha256=K1Paf3JNS3nY907ZhPn1BZ3EiVDURjsEdLmyNeoSVFk,11057
34
- nucliadb_telemetry-6.4.0.post4171.dist-info/WHEEL,sha256=ooBFpIzZCPdw3uqIQsOo4qqbA4ZRPxHnOH7peeONza0,91
35
- nucliadb_telemetry-6.4.0.post4171.dist-info/top_level.txt,sha256=3qEHI_5ttqQIL2gkNYwSlKsFyBBiEzDiIy9UKISzOaQ,19
36
- nucliadb_telemetry-6.4.0.post4171.dist-info/RECORD,,
33
+ nucliadb_telemetry-6.4.0.post4184.dist-info/METADATA,sha256=cM_ssIHA_F4TjqTkd9FqeM_VkcpYfqx5VJ9XtsunbyU,11057
34
+ nucliadb_telemetry-6.4.0.post4184.dist-info/WHEEL,sha256=ooBFpIzZCPdw3uqIQsOo4qqbA4ZRPxHnOH7peeONza0,91
35
+ nucliadb_telemetry-6.4.0.post4184.dist-info/top_level.txt,sha256=3qEHI_5ttqQIL2gkNYwSlKsFyBBiEzDiIy9UKISzOaQ,19
36
+ nucliadb_telemetry-6.4.0.post4184.dist-info/RECORD,,