nucliadb-telemetry 6.4.0.post4167__py3-none-any.whl → 6.4.0.post4176__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.
- nucliadb_telemetry/jetstream.py +49 -31
- {nucliadb_telemetry-6.4.0.post4167.dist-info → nucliadb_telemetry-6.4.0.post4176.dist-info}/METADATA +1 -1
- {nucliadb_telemetry-6.4.0.post4167.dist-info → nucliadb_telemetry-6.4.0.post4176.dist-info}/RECORD +5 -5
- {nucliadb_telemetry-6.4.0.post4167.dist-info → nucliadb_telemetry-6.4.0.post4176.dist-info}/WHEEL +0 -0
- {nucliadb_telemetry-6.4.0.post4167.dist-info → nucliadb_telemetry-6.4.0.post4176.dist-info}/top_level.txt +0 -0
nucliadb_telemetry/jetstream.py
CHANGED
|
@@ -19,12 +19,13 @@
|
|
|
19
19
|
|
|
20
20
|
from datetime import datetime
|
|
21
21
|
from functools import partial
|
|
22
|
-
from typing import Any, Callable, Dict, List, Optional, Union
|
|
22
|
+
from typing import Any, Awaitable, Callable, Dict, List, Optional, Union
|
|
23
23
|
from urllib.parse import ParseResult
|
|
24
24
|
|
|
25
25
|
import nats
|
|
26
26
|
from nats.aio.client import Client
|
|
27
27
|
from nats.aio.msg import Msg
|
|
28
|
+
from nats.aio.subscription import Subscription
|
|
28
29
|
from nats.js.client import JetStreamContext
|
|
29
30
|
from opentelemetry.propagate import extract, inject
|
|
30
31
|
from opentelemetry.sdk.trace import TracerProvider
|
|
@@ -71,7 +72,7 @@ def start_span_message_receiver(tracer: Tracer, msg: Msg):
|
|
|
71
72
|
}
|
|
72
73
|
|
|
73
74
|
# add some attributes from the metadata
|
|
74
|
-
ctx = extract(msg.headers)
|
|
75
|
+
ctx = extract(msg.headers or {})
|
|
75
76
|
|
|
76
77
|
span = tracer.start_as_current_span(
|
|
77
78
|
name=f"Received from {msg.subject}",
|
|
@@ -97,6 +98,24 @@ def start_span_message_publisher(tracer: Tracer, subject: str):
|
|
|
97
98
|
return span
|
|
98
99
|
|
|
99
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
|
+
|
|
100
119
|
class JetStreamContextTelemetry:
|
|
101
120
|
def __init__(self, js: JetStreamContext, service_name: str, tracer_provider: TracerProvider):
|
|
102
121
|
self.js = js
|
|
@@ -109,34 +128,20 @@ class JetStreamContextTelemetry:
|
|
|
109
128
|
async def add_stream(self, name: str, subjects: List[str]):
|
|
110
129
|
return await self.js.add_stream(name=name, subjects=subjects)
|
|
111
130
|
|
|
112
|
-
async def subscribe(
|
|
131
|
+
async def subscribe(
|
|
132
|
+
self,
|
|
133
|
+
subject: str,
|
|
134
|
+
queue: Optional[str] = None,
|
|
135
|
+
cb: Optional[Callable[[Msg], Awaitable[None]]] = None,
|
|
136
|
+
**kwargs,
|
|
137
|
+
):
|
|
113
138
|
tracer = self.tracer_provider.get_tracer(f"{self.service_name}_js_subscriber")
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
return
|
|
121
|
-
|
|
122
|
-
with start_span_message_receiver(tracer, msg) as span:
|
|
123
|
-
try:
|
|
124
|
-
await origin_cb(msg)
|
|
125
|
-
except Exception as error:
|
|
126
|
-
set_span_exception(span, error)
|
|
127
|
-
raise error
|
|
128
|
-
finally:
|
|
129
|
-
msg_consume_time_histo.observe(
|
|
130
|
-
(datetime.now() - msg.metadata.timestamp).total_seconds(),
|
|
131
|
-
{
|
|
132
|
-
"stream": msg.metadata.stream,
|
|
133
|
-
"consumer": msg.metadata.consumer or "",
|
|
134
|
-
"acked": "yes" if msg._ackd else "no", # type: ignore
|
|
135
|
-
},
|
|
136
|
-
)
|
|
137
|
-
|
|
138
|
-
wrapped_cb = partial(wrapper, cb, tracer)
|
|
139
|
-
return await self.js.subscribe(cb=wrapped_cb, **kwargs)
|
|
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
|
|
144
|
+
return await self.js.subscribe(subject, queue=queue, cb=wrapped_cb, **kwargs)
|
|
140
145
|
|
|
141
146
|
async def publish(
|
|
142
147
|
self,
|
|
@@ -159,6 +164,10 @@ class JetStreamContextTelemetry:
|
|
|
159
164
|
|
|
160
165
|
return result
|
|
161
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
|
+
|
|
162
171
|
# Just for convenience, to wrap all we use in the context of
|
|
163
172
|
# telemetry-instrumented stuff using the JetStreamContextTelemetry class
|
|
164
173
|
|
|
@@ -217,7 +226,13 @@ class NatsClientTelemetry:
|
|
|
217
226
|
self.service_name = service_name
|
|
218
227
|
self.tracer_provider = tracer_provider
|
|
219
228
|
|
|
220
|
-
async def subscribe(
|
|
229
|
+
async def subscribe(
|
|
230
|
+
self,
|
|
231
|
+
subject: str,
|
|
232
|
+
queue: str = "",
|
|
233
|
+
cb: Optional[Callable[[Msg], Awaitable[None]]] = None,
|
|
234
|
+
**kwargs,
|
|
235
|
+
) -> Subscription:
|
|
221
236
|
tracer = self.tracer_provider.get_tracer(f"{self.service_name}_nc_subscriber")
|
|
222
237
|
|
|
223
238
|
async def wrapper(origin_cb, tracer, msg: Msg):
|
|
@@ -235,7 +250,7 @@ class NatsClientTelemetry:
|
|
|
235
250
|
raise error
|
|
236
251
|
|
|
237
252
|
wrapped_cb = partial(wrapper, cb, tracer)
|
|
238
|
-
return await self.nc.subscribe(cb=wrapped_cb, **kwargs)
|
|
253
|
+
return await self.nc.subscribe(subject, queue=queue, cb=wrapped_cb, **kwargs)
|
|
239
254
|
|
|
240
255
|
async def publish(
|
|
241
256
|
self,
|
|
@@ -290,6 +305,9 @@ class NatsClientTelemetry:
|
|
|
290
305
|
def jetstream(self, **opts) -> nats.js.JetStreamContext:
|
|
291
306
|
return self.nc.jetstream(**opts)
|
|
292
307
|
|
|
308
|
+
def jsm(self, **opts) -> nats.js.JetStreamManager:
|
|
309
|
+
return self.nc.jsm(**opts)
|
|
310
|
+
|
|
293
311
|
async def drain(self) -> None:
|
|
294
312
|
return await self.nc.drain()
|
|
295
313
|
|
{nucliadb_telemetry-6.4.0.post4167.dist-info → nucliadb_telemetry-6.4.0.post4176.dist-info}/RECORD
RENAMED
|
@@ -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=
|
|
10
|
+
nucliadb_telemetry/jetstream.py,sha256=PAkteKgKI5zwRzvEn5Uv1sGHykug2wp4bp5H6vSd-PE,12041
|
|
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.
|
|
34
|
-
nucliadb_telemetry-6.4.0.
|
|
35
|
-
nucliadb_telemetry-6.4.0.
|
|
36
|
-
nucliadb_telemetry-6.4.0.
|
|
33
|
+
nucliadb_telemetry-6.4.0.post4176.dist-info/METADATA,sha256=5NyvhROrahLGQUu7zDTvQ4CAPXRDTF3o78W6gxQBHn4,11057
|
|
34
|
+
nucliadb_telemetry-6.4.0.post4176.dist-info/WHEEL,sha256=ooBFpIzZCPdw3uqIQsOo4qqbA4ZRPxHnOH7peeONza0,91
|
|
35
|
+
nucliadb_telemetry-6.4.0.post4176.dist-info/top_level.txt,sha256=3qEHI_5ttqQIL2gkNYwSlKsFyBBiEzDiIy9UKISzOaQ,19
|
|
36
|
+
nucliadb_telemetry-6.4.0.post4176.dist-info/RECORD,,
|
{nucliadb_telemetry-6.4.0.post4167.dist-info → nucliadb_telemetry-6.4.0.post4176.dist-info}/WHEEL
RENAMED
|
File without changes
|
|
File without changes
|