opentelemetry-python-contrib-external-valkey 0.63b1__tar.gz → 0.65b0__tar.gz
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.
- {opentelemetry_python_contrib_external_valkey-0.63b1 → opentelemetry_python_contrib_external_valkey-0.65b0}/PKG-INFO +3 -3
- opentelemetry_python_contrib_external_valkey-0.65b0/pyproject.toml +43 -0
- opentelemetry_python_contrib_external_valkey-0.63b1/pyproject.toml → opentelemetry_python_contrib_external_valkey-0.65b0/pyproject.toml.orig +4 -4
- {opentelemetry_python_contrib_external_valkey-0.63b1 → opentelemetry_python_contrib_external_valkey-0.65b0}/src/opentelemetry/instrumentation/valkey/__init__.py +141 -37
- {opentelemetry_python_contrib_external_valkey-0.63b1 → opentelemetry_python_contrib_external_valkey-0.65b0}/src/opentelemetry/instrumentation/valkey/custom_types.py +1 -12
- opentelemetry_python_contrib_external_valkey-0.65b0/src/opentelemetry/instrumentation/valkey/package.py +8 -0
- {opentelemetry_python_contrib_external_valkey-0.63b1 → opentelemetry_python_contrib_external_valkey-0.65b0}/src/opentelemetry/instrumentation/valkey/util.py +55 -32
- opentelemetry_python_contrib_external_valkey-0.65b0/src/opentelemetry/instrumentation/valkey/version.py +5 -0
- opentelemetry_python_contrib_external_valkey-0.63b1/src/opentelemetry/instrumentation/valkey/package.py +0 -16
- opentelemetry_python_contrib_external_valkey-0.63b1/src/opentelemetry/instrumentation/valkey/version.py +0 -16
- {opentelemetry_python_contrib_external_valkey-0.63b1 → opentelemetry_python_contrib_external_valkey-0.65b0}/LICENSE +0 -0
- {opentelemetry_python_contrib_external_valkey-0.63b1 → opentelemetry_python_contrib_external_valkey-0.65b0}/README.md +0 -0
- {opentelemetry_python_contrib_external_valkey-0.63b1 → opentelemetry_python_contrib_external_valkey-0.65b0}/src/opentelemetry/instrumentation/valkey/py.typed +0 -0
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: opentelemetry-python-contrib-external-valkey
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.65b0
|
|
4
4
|
Summary: OpenTelemetry Valkey instrumentation
|
|
5
5
|
Author: Philip Meier
|
|
6
6
|
Author-email: Philip Meier <github.pmeier@posteo.de>
|
|
7
7
|
License-Expression: Apache-2.0
|
|
8
8
|
License-File: LICENSE
|
|
9
9
|
Requires-Dist: opentelemetry-api~=1.12
|
|
10
|
-
Requires-Dist: opentelemetry-instrumentation==0.
|
|
11
|
-
Requires-Dist: opentelemetry-semantic-conventions==0.
|
|
10
|
+
Requires-Dist: opentelemetry-instrumentation==0.65b0
|
|
11
|
+
Requires-Dist: opentelemetry-semantic-conventions==0.65b0
|
|
12
12
|
Requires-Dist: wrapt>=1.12.1
|
|
13
13
|
Requires-Python: >=3.10
|
|
14
14
|
Description-Content-Type: text/markdown
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "opentelemetry-python-contrib-external-valkey"
|
|
3
|
+
description = "OpenTelemetry Valkey instrumentation"
|
|
4
|
+
license = "Apache-2.0"
|
|
5
|
+
license-files = ["LICENSE"]
|
|
6
|
+
readme = "README.md"
|
|
7
|
+
requires-python = ">=3.10"
|
|
8
|
+
version = "0.65b0"
|
|
9
|
+
dependencies = [
|
|
10
|
+
"opentelemetry-api~=1.12",
|
|
11
|
+
"opentelemetry-instrumentation==0.65b0",
|
|
12
|
+
"opentelemetry-semantic-conventions==0.65b0",
|
|
13
|
+
"wrapt>=1.12.1",
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
[[project.authors]]
|
|
17
|
+
name = "Philip Meier"
|
|
18
|
+
email = "github.pmeier@posteo.de"
|
|
19
|
+
|
|
20
|
+
[project.entry-points.opentelemetry_instrumentor]
|
|
21
|
+
redis = "opentelemetry.instrumentation.valkey:ValkeyInstrumentor"
|
|
22
|
+
|
|
23
|
+
[dependency-groups]
|
|
24
|
+
instruments = ["valkey>=6.1.0"]
|
|
25
|
+
dev = [
|
|
26
|
+
{ include-group = "instruments" },
|
|
27
|
+
"fakeredis>=2.25",
|
|
28
|
+
"opentelemetry-test-utils==0.65b0",
|
|
29
|
+
"pytest>=7.4.4",
|
|
30
|
+
"pytest-asyncio>=1.2.0",
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
[build-system]
|
|
34
|
+
requires = ["uv_build>=0.9.11,<0.10.0"]
|
|
35
|
+
build-backend = "uv_build"
|
|
36
|
+
|
|
37
|
+
[tool.uv.build-backend]
|
|
38
|
+
module-name = "opentelemetry.instrumentation.valkey"
|
|
39
|
+
|
|
40
|
+
[tool.pytest.ini_options]
|
|
41
|
+
minversion = "6.0"
|
|
42
|
+
addopts = "-ra --tb=short"
|
|
43
|
+
testpaths = ["tests"]
|
|
@@ -8,12 +8,12 @@ authors = [
|
|
|
8
8
|
]
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
11
|
-
version = "0.
|
|
11
|
+
version = "0.65b0"
|
|
12
12
|
|
|
13
13
|
dependencies = [
|
|
14
14
|
"opentelemetry-api~=1.12",
|
|
15
|
-
"opentelemetry-instrumentation==0.
|
|
16
|
-
"opentelemetry-semantic-conventions==0.
|
|
15
|
+
"opentelemetry-instrumentation==0.65b0",
|
|
16
|
+
"opentelemetry-semantic-conventions==0.65b0",
|
|
17
17
|
"wrapt>=1.12.1",
|
|
18
18
|
]
|
|
19
19
|
|
|
@@ -22,7 +22,7 @@ instruments = ["valkey>=6.1.0"]
|
|
|
22
22
|
dev = [
|
|
23
23
|
{include-group = "instruments"},
|
|
24
24
|
"fakeredis>=2.25",
|
|
25
|
-
"opentelemetry-test-utils==0.
|
|
25
|
+
"opentelemetry-test-utils==0.65b0",
|
|
26
26
|
"pytest>=7.4.4",
|
|
27
27
|
"pytest-asyncio>=1.2.0",
|
|
28
28
|
]
|
|
@@ -1,18 +1,7 @@
|
|
|
1
1
|
# Copyright The OpenTelemetry Authors
|
|
2
2
|
# Copyright 2025 Philip Meier
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
4
|
#
|
|
4
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
# you may not use this file except in compliance with the License.
|
|
6
|
-
# You may obtain a copy of the License at
|
|
7
|
-
#
|
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
#
|
|
10
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
# See the License for the specific language governing permissions and
|
|
14
|
-
# limitations under the License.
|
|
15
|
-
|
|
16
5
|
"""
|
|
17
6
|
Instrument `valkey`_ to report Valkey queries.
|
|
18
7
|
|
|
@@ -153,6 +142,13 @@ import valkey
|
|
|
153
142
|
from wrapt import wrap_function_wrapper
|
|
154
143
|
|
|
155
144
|
from opentelemetry import trace
|
|
145
|
+
from opentelemetry.instrumentation._semconv import (
|
|
146
|
+
_get_schema_url_for_signal_types,
|
|
147
|
+
_get_semconv_opt_in_modes,
|
|
148
|
+
_OpenTelemetrySemanticConventionStability,
|
|
149
|
+
_OpenTelemetryStabilitySignalType,
|
|
150
|
+
_set_db_statement,
|
|
151
|
+
)
|
|
156
152
|
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
|
|
157
153
|
from opentelemetry.instrumentation.valkey.package import _instruments
|
|
158
154
|
from opentelemetry.instrumentation.valkey.util import (
|
|
@@ -168,9 +164,6 @@ from opentelemetry.instrumentation.utils import (
|
|
|
168
164
|
is_instrumentation_enabled,
|
|
169
165
|
unwrap,
|
|
170
166
|
)
|
|
171
|
-
from opentelemetry.semconv._incubating.attributes.db_attributes import (
|
|
172
|
-
DB_STATEMENT,
|
|
173
|
-
)
|
|
174
167
|
from opentelemetry.trace import (
|
|
175
168
|
StatusCode,
|
|
176
169
|
Tracer,
|
|
@@ -218,11 +211,32 @@ if _CLIENT_ASYNCIO_SUPPORT:
|
|
|
218
211
|
_INSTRUMENTATION_ATTR = "_is_instrumented_by_opentelemetry"
|
|
219
212
|
|
|
220
213
|
|
|
214
|
+
def _execute_hook(hook: Callable[..., None], *args: Any) -> None:
|
|
215
|
+
try:
|
|
216
|
+
hook(*args)
|
|
217
|
+
# pylint: disable-next=broad-exception-caught
|
|
218
|
+
except Exception:
|
|
219
|
+
_logger.warning("Exception raised by hook %r", hook, exc_info=True)
|
|
220
|
+
|
|
221
|
+
|
|
221
222
|
def _traced_execute_factory(
|
|
222
223
|
tracer: Tracer,
|
|
223
224
|
request_hook: RequestHook | None = None,
|
|
224
225
|
response_hook: ResponseHook | None = None,
|
|
225
226
|
):
|
|
227
|
+
sem_conv_opt_in_modes = _get_semconv_opt_in_modes(
|
|
228
|
+
(
|
|
229
|
+
_OpenTelemetryStabilitySignalType.DATABASE,
|
|
230
|
+
_OpenTelemetryStabilitySignalType.HTTP,
|
|
231
|
+
)
|
|
232
|
+
)
|
|
233
|
+
db_sem_conv_opt_in_mode = sem_conv_opt_in_modes[
|
|
234
|
+
_OpenTelemetryStabilitySignalType.DATABASE
|
|
235
|
+
]
|
|
236
|
+
http_sem_conv_opt_in_mode = sem_conv_opt_in_modes[
|
|
237
|
+
_OpenTelemetryStabilitySignalType.HTTP
|
|
238
|
+
]
|
|
239
|
+
|
|
226
240
|
def _traced_execute_command(
|
|
227
241
|
func: Callable[..., R],
|
|
228
242
|
instance: ValkeyInstance,
|
|
@@ -238,19 +252,30 @@ def _traced_execute_factory(
|
|
|
238
252
|
name, kind=trace.SpanKind.CLIENT
|
|
239
253
|
) as span:
|
|
240
254
|
if span.is_recording():
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
255
|
+
span_attrs = {}
|
|
256
|
+
_set_db_statement(span_attrs, query, db_sem_conv_opt_in_mode)
|
|
257
|
+
span_attrs["db.valkey.args_length"] = len(args)
|
|
258
|
+
|
|
259
|
+
# Set all DB attributes
|
|
260
|
+
for key, value in span_attrs.items():
|
|
261
|
+
span.set_attribute(key, value)
|
|
262
|
+
|
|
263
|
+
_set_connection_attributes(
|
|
264
|
+
span,
|
|
265
|
+
instance,
|
|
266
|
+
db_sem_conv_opt_in_mode,
|
|
267
|
+
http_sem_conv_opt_in_mode,
|
|
268
|
+
)
|
|
244
269
|
if span.name == "valkey.create_index":
|
|
245
270
|
_add_create_attributes(span, args)
|
|
246
271
|
if callable(request_hook):
|
|
247
|
-
request_hook
|
|
272
|
+
_execute_hook(request_hook, span, instance, args, kwargs)
|
|
248
273
|
response = func(*args, **kwargs)
|
|
249
274
|
if span.is_recording():
|
|
250
275
|
if span.name == "valkey.search":
|
|
251
276
|
_add_search_attributes(span, response, args)
|
|
252
277
|
if callable(response_hook):
|
|
253
|
-
response_hook
|
|
278
|
+
_execute_hook(response_hook, span, instance, response)
|
|
254
279
|
return response
|
|
255
280
|
|
|
256
281
|
return _traced_execute_command
|
|
@@ -261,6 +286,19 @@ def _traced_execute_pipeline_factory(
|
|
|
261
286
|
request_hook: RequestHook | None = None,
|
|
262
287
|
response_hook: ResponseHook | None = None,
|
|
263
288
|
):
|
|
289
|
+
sem_conv_opt_in_modes = _get_semconv_opt_in_modes(
|
|
290
|
+
(
|
|
291
|
+
_OpenTelemetryStabilitySignalType.DATABASE,
|
|
292
|
+
_OpenTelemetryStabilitySignalType.HTTP,
|
|
293
|
+
)
|
|
294
|
+
)
|
|
295
|
+
db_sem_conv_opt_in_mode = sem_conv_opt_in_modes[
|
|
296
|
+
_OpenTelemetryStabilitySignalType.DATABASE
|
|
297
|
+
]
|
|
298
|
+
http_sem_conv_opt_in_mode = sem_conv_opt_in_modes[
|
|
299
|
+
_OpenTelemetryStabilitySignalType.HTTP
|
|
300
|
+
]
|
|
301
|
+
|
|
264
302
|
def _traced_execute_pipeline(
|
|
265
303
|
func: Callable[..., R],
|
|
266
304
|
instance: PipelineInstance,
|
|
@@ -280,10 +318,21 @@ def _traced_execute_pipeline_factory(
|
|
|
280
318
|
span_name, kind=trace.SpanKind.CLIENT
|
|
281
319
|
) as span:
|
|
282
320
|
if span.is_recording():
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
321
|
+
span_attrs = {}
|
|
322
|
+
_set_db_statement(
|
|
323
|
+
span_attrs, resource, db_sem_conv_opt_in_mode
|
|
324
|
+
)
|
|
325
|
+
span_attrs["db.valkey.pipeline_length"] = len(command_stack)
|
|
326
|
+
|
|
327
|
+
# Set all DB attributes
|
|
328
|
+
for key, value in span_attrs.items():
|
|
329
|
+
span.set_attribute(key, value)
|
|
330
|
+
|
|
331
|
+
_set_connection_attributes(
|
|
332
|
+
span,
|
|
333
|
+
instance,
|
|
334
|
+
db_sem_conv_opt_in_mode,
|
|
335
|
+
http_sem_conv_opt_in_mode,
|
|
287
336
|
)
|
|
288
337
|
|
|
289
338
|
response = None
|
|
@@ -294,7 +343,7 @@ def _traced_execute_pipeline_factory(
|
|
|
294
343
|
exception = watch_exception
|
|
295
344
|
|
|
296
345
|
if callable(response_hook):
|
|
297
|
-
response_hook
|
|
346
|
+
_execute_hook(response_hook, span, instance, response)
|
|
298
347
|
|
|
299
348
|
if exception:
|
|
300
349
|
raise exception
|
|
@@ -309,6 +358,19 @@ def _async_traced_execute_factory(
|
|
|
309
358
|
request_hook: RequestHook | None = None,
|
|
310
359
|
response_hook: ResponseHook | None = None,
|
|
311
360
|
):
|
|
361
|
+
sem_conv_opt_in_modes = _get_semconv_opt_in_modes(
|
|
362
|
+
(
|
|
363
|
+
_OpenTelemetryStabilitySignalType.DATABASE,
|
|
364
|
+
_OpenTelemetryStabilitySignalType.HTTP,
|
|
365
|
+
)
|
|
366
|
+
)
|
|
367
|
+
db_sem_conv_opt_in_mode = sem_conv_opt_in_modes[
|
|
368
|
+
_OpenTelemetryStabilitySignalType.DATABASE
|
|
369
|
+
]
|
|
370
|
+
http_sem_conv_opt_in_mode = sem_conv_opt_in_modes[
|
|
371
|
+
_OpenTelemetryStabilitySignalType.HTTP
|
|
372
|
+
]
|
|
373
|
+
|
|
312
374
|
async def _async_traced_execute_command(
|
|
313
375
|
func: Callable[..., Awaitable[R]],
|
|
314
376
|
instance: AsyncValkeyInstance,
|
|
@@ -325,14 +387,25 @@ def _async_traced_execute_factory(
|
|
|
325
387
|
name, kind=trace.SpanKind.CLIENT
|
|
326
388
|
) as span:
|
|
327
389
|
if span.is_recording():
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
390
|
+
span_attrs = {}
|
|
391
|
+
_set_db_statement(span_attrs, query, db_sem_conv_opt_in_mode)
|
|
392
|
+
span_attrs["db.valkey.args_length"] = len(args)
|
|
393
|
+
|
|
394
|
+
# Set all DB attributes
|
|
395
|
+
for key, value in span_attrs.items():
|
|
396
|
+
span.set_attribute(key, value)
|
|
397
|
+
|
|
398
|
+
_set_connection_attributes(
|
|
399
|
+
span,
|
|
400
|
+
instance,
|
|
401
|
+
db_sem_conv_opt_in_mode,
|
|
402
|
+
http_sem_conv_opt_in_mode,
|
|
403
|
+
)
|
|
331
404
|
if callable(request_hook):
|
|
332
|
-
request_hook
|
|
405
|
+
_execute_hook(request_hook, span, instance, args, kwargs)
|
|
333
406
|
response = await func(*args, **kwargs)
|
|
334
407
|
if callable(response_hook):
|
|
335
|
-
response_hook
|
|
408
|
+
_execute_hook(response_hook, span, instance, response)
|
|
336
409
|
return response
|
|
337
410
|
|
|
338
411
|
return _async_traced_execute_command
|
|
@@ -343,6 +416,19 @@ def _async_traced_execute_pipeline_factory(
|
|
|
343
416
|
request_hook: RequestHook | None = None,
|
|
344
417
|
response_hook: ResponseHook | None = None,
|
|
345
418
|
):
|
|
419
|
+
sem_conv_opt_in_modes = _get_semconv_opt_in_modes(
|
|
420
|
+
(
|
|
421
|
+
_OpenTelemetryStabilitySignalType.DATABASE,
|
|
422
|
+
_OpenTelemetryStabilitySignalType.HTTP,
|
|
423
|
+
)
|
|
424
|
+
)
|
|
425
|
+
db_sem_conv_opt_in_mode = sem_conv_opt_in_modes[
|
|
426
|
+
_OpenTelemetryStabilitySignalType.DATABASE
|
|
427
|
+
]
|
|
428
|
+
http_sem_conv_opt_in_mode = sem_conv_opt_in_modes[
|
|
429
|
+
_OpenTelemetryStabilitySignalType.HTTP
|
|
430
|
+
]
|
|
431
|
+
|
|
346
432
|
async def _async_traced_execute_pipeline(
|
|
347
433
|
func: Callable[..., Awaitable[R]],
|
|
348
434
|
instance: AsyncPipelineInstance,
|
|
@@ -364,10 +450,21 @@ def _async_traced_execute_pipeline_factory(
|
|
|
364
450
|
span_name, kind=trace.SpanKind.CLIENT
|
|
365
451
|
) as span:
|
|
366
452
|
if span.is_recording():
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
453
|
+
span_attrs = {}
|
|
454
|
+
_set_db_statement(
|
|
455
|
+
span_attrs, resource, db_sem_conv_opt_in_mode
|
|
456
|
+
)
|
|
457
|
+
span_attrs["db.valkey.pipeline_length"] = len(command_stack)
|
|
458
|
+
|
|
459
|
+
# Set all DB attributes
|
|
460
|
+
for key, value in span_attrs.items():
|
|
461
|
+
span.set_attribute(key, value)
|
|
462
|
+
|
|
463
|
+
_set_connection_attributes(
|
|
464
|
+
span,
|
|
465
|
+
instance,
|
|
466
|
+
db_sem_conv_opt_in_mode,
|
|
467
|
+
http_sem_conv_opt_in_mode,
|
|
371
468
|
)
|
|
372
469
|
|
|
373
470
|
response = None
|
|
@@ -378,7 +475,7 @@ def _async_traced_execute_pipeline_factory(
|
|
|
378
475
|
exception = watch_exception
|
|
379
476
|
|
|
380
477
|
if callable(response_hook):
|
|
381
|
-
response_hook
|
|
478
|
+
_execute_hook(response_hook, span, instance, response)
|
|
382
479
|
|
|
383
480
|
if exception:
|
|
384
481
|
raise exception
|
|
@@ -541,12 +638,20 @@ def _instrument_client(
|
|
|
541
638
|
class ValkeyInstrumentor(BaseInstrumentor):
|
|
542
639
|
@staticmethod
|
|
543
640
|
def _get_tracer(**kwargs):
|
|
641
|
+
# Initialize semantic conventions opt-in if needed
|
|
642
|
+
_OpenTelemetrySemanticConventionStability._initialize()
|
|
643
|
+
# Valkey instrumentation supports both DATABASE and HTTP signal types
|
|
644
|
+
signal_types = [
|
|
645
|
+
_OpenTelemetryStabilitySignalType.DATABASE,
|
|
646
|
+
_OpenTelemetryStabilitySignalType.HTTP,
|
|
647
|
+
]
|
|
648
|
+
|
|
544
649
|
tracer_provider = kwargs.get("tracer_provider")
|
|
545
650
|
return get_tracer(
|
|
546
651
|
__name__,
|
|
547
652
|
__version__,
|
|
548
653
|
tracer_provider=tracer_provider,
|
|
549
|
-
schema_url=
|
|
654
|
+
schema_url=_get_schema_url_for_signal_types(signal_types),
|
|
550
655
|
)
|
|
551
656
|
|
|
552
657
|
def instrument(
|
|
@@ -699,7 +804,6 @@ class ValkeyInstrumentor(BaseInstrumentor):
|
|
|
699
804
|
_logger.warning(
|
|
700
805
|
"Attempting to un-instrument Valkey connection that wasn't instrumented"
|
|
701
806
|
)
|
|
702
|
-
return
|
|
703
807
|
|
|
704
808
|
def instrumentation_dependencies(self) -> Collection[str]:
|
|
705
809
|
"""Return a list of python packages with versions that the will be instrumented."""
|
|
@@ -1,17 +1,6 @@
|
|
|
1
1
|
# Copyright The OpenTelemetry Authors
|
|
2
2
|
# Copyright 2025 Philip Meier
|
|
3
|
-
#
|
|
4
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
# you may not use this file except in compliance with the License.
|
|
6
|
-
# You may obtain a copy of the License at
|
|
7
|
-
#
|
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
#
|
|
10
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
# See the License for the specific language governing permissions and
|
|
14
|
-
# limitations under the License.
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
15
4
|
|
|
16
5
|
from __future__ import annotations
|
|
17
6
|
|
|
@@ -1,18 +1,7 @@
|
|
|
1
1
|
# Copyright The OpenTelemetry Authors
|
|
2
2
|
# Copyright 2025 Philip Meier
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
4
|
#
|
|
4
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
# you may not use this file except in compliance with the License.
|
|
6
|
-
# You may obtain a copy of the License at
|
|
7
|
-
#
|
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
#
|
|
10
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
# See the License for the specific language governing permissions and
|
|
14
|
-
# limitations under the License.
|
|
15
|
-
|
|
16
5
|
"""
|
|
17
6
|
Some utils used by the valkey integration
|
|
18
7
|
"""
|
|
@@ -21,14 +10,15 @@ from __future__ import annotations
|
|
|
21
10
|
|
|
22
11
|
from typing import TYPE_CHECKING, Any
|
|
23
12
|
|
|
24
|
-
from opentelemetry.
|
|
25
|
-
|
|
26
|
-
|
|
13
|
+
from opentelemetry.instrumentation._semconv import (
|
|
14
|
+
_set_db_redis_database_index,
|
|
15
|
+
_set_db_system,
|
|
16
|
+
_set_http_net_peer_name_client,
|
|
17
|
+
_set_http_peer_port_client,
|
|
18
|
+
_set_net_transport,
|
|
27
19
|
)
|
|
28
|
-
from opentelemetry.semconv.
|
|
29
|
-
|
|
30
|
-
NET_PEER_PORT,
|
|
31
|
-
NET_TRANSPORT,
|
|
20
|
+
from opentelemetry.semconv.attributes.network_attributes import (
|
|
21
|
+
NetworkTransportValues,
|
|
32
22
|
)
|
|
33
23
|
from opentelemetry.semconv.trace import (
|
|
34
24
|
DbSystemValues,
|
|
@@ -47,20 +37,44 @@ if TYPE_CHECKING:
|
|
|
47
37
|
_FIELD_TYPES = ["NUMERIC", "TEXT", "GEO", "TAG", "VECTOR"]
|
|
48
38
|
|
|
49
39
|
|
|
50
|
-
def _extract_conn_attributes(
|
|
40
|
+
def _extract_conn_attributes(
|
|
41
|
+
conn_kwargs, db_sem_conv_opt_in_mode, http_sem_conv_opt_in_mode
|
|
42
|
+
):
|
|
51
43
|
"""Transform valkey conn info into dict"""
|
|
52
|
-
attributes = {
|
|
53
|
-
|
|
54
|
-
|
|
44
|
+
attributes = {}
|
|
45
|
+
_set_db_system(
|
|
46
|
+
attributes, DbSystemValues.REDIS.value, db_sem_conv_opt_in_mode
|
|
47
|
+
)
|
|
48
|
+
|
|
55
49
|
db = conn_kwargs.get("db", 0)
|
|
56
|
-
attributes
|
|
50
|
+
_set_db_redis_database_index(attributes, db, db_sem_conv_opt_in_mode)
|
|
57
51
|
if "path" in conn_kwargs:
|
|
58
|
-
|
|
59
|
-
|
|
52
|
+
_set_http_net_peer_name_client(
|
|
53
|
+
attributes, conn_kwargs.get("path", ""), http_sem_conv_opt_in_mode
|
|
54
|
+
)
|
|
55
|
+
_set_net_transport(
|
|
56
|
+
attributes,
|
|
57
|
+
NetTransportValues.OTHER.value,
|
|
58
|
+
NetworkTransportValues.UNIX.value,
|
|
59
|
+
http_sem_conv_opt_in_mode,
|
|
60
|
+
)
|
|
60
61
|
else:
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
_set_http_net_peer_name_client(
|
|
63
|
+
attributes,
|
|
64
|
+
conn_kwargs.get("host", "localhost"),
|
|
65
|
+
http_sem_conv_opt_in_mode,
|
|
66
|
+
)
|
|
67
|
+
_set_http_peer_port_client(
|
|
68
|
+
attributes,
|
|
69
|
+
conn_kwargs.get("port", 6379),
|
|
70
|
+
http_sem_conv_opt_in_mode,
|
|
71
|
+
)
|
|
72
|
+
_set_net_transport(
|
|
73
|
+
attributes,
|
|
74
|
+
NetTransportValues.IP_TCP.value,
|
|
75
|
+
NetworkTransportValues.TCP.value,
|
|
76
|
+
http_sem_conv_opt_in_mode,
|
|
77
|
+
)
|
|
64
78
|
|
|
65
79
|
return attributes
|
|
66
80
|
|
|
@@ -100,12 +114,21 @@ def _value_or_none(values, n):
|
|
|
100
114
|
|
|
101
115
|
|
|
102
116
|
def _set_connection_attributes(
|
|
103
|
-
span: Span,
|
|
117
|
+
span: Span,
|
|
118
|
+
conn: ValkeyInstance | AsyncValkeyInstance,
|
|
119
|
+
db_sem_conv_opt_in_mode,
|
|
120
|
+
http_sem_conv_opt_in_mode,
|
|
104
121
|
) -> None:
|
|
105
|
-
if
|
|
122
|
+
if (
|
|
123
|
+
not span.is_recording()
|
|
124
|
+
or not hasattr(conn, "connection_pool")
|
|
125
|
+
or not hasattr(conn.connection_pool, "connection_kwargs")
|
|
126
|
+
):
|
|
106
127
|
return
|
|
107
128
|
for key, value in _extract_conn_attributes(
|
|
108
|
-
conn.connection_pool.connection_kwargs
|
|
129
|
+
conn.connection_pool.connection_kwargs,
|
|
130
|
+
db_sem_conv_opt_in_mode,
|
|
131
|
+
http_sem_conv_opt_in_mode,
|
|
109
132
|
).items():
|
|
110
133
|
span.set_attribute(key, value)
|
|
111
134
|
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
# Copyright The OpenTelemetry Authors
|
|
2
|
-
# Copyright 2025 Philip Meier
|
|
3
|
-
#
|
|
4
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
# you may not use this file except in compliance with the License.
|
|
6
|
-
# You may obtain a copy of the License at
|
|
7
|
-
#
|
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
#
|
|
10
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
# See the License for the specific language governing permissions and
|
|
14
|
-
# limitations under the License.
|
|
15
|
-
|
|
16
|
-
_instruments = ("valkey >= 6.1.0",)
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
# Copyright The OpenTelemetry Authors
|
|
2
|
-
# Copyright 2025 Philip Meier
|
|
3
|
-
#
|
|
4
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
# you may not use this file except in compliance with the License.
|
|
6
|
-
# You may obtain a copy of the License at
|
|
7
|
-
#
|
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
#
|
|
10
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
# See the License for the specific language governing permissions and
|
|
14
|
-
# limitations under the License.
|
|
15
|
-
|
|
16
|
-
__version__ = "0.63b1"
|
|
File without changes
|
|
File without changes
|