ctxflow-semconv 0.2.2__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.
@@ -0,0 +1,53 @@
1
+ """ctxflow semantic conventions: C1-C7 constants, JSON Schema and dialect maps."""
2
+
3
+ import re
4
+ from functools import lru_cache
5
+ from importlib.resources import files
6
+ from importlib.resources.abc import Traversable
7
+ from typing import Final
8
+
9
+ from ctxflow_semconv._generated import * # noqa: F403
10
+ from ctxflow_semconv._generated import DIALECTS, ContentKind
11
+ from ctxflow_semconv._generated import __all__ as _generated_all
12
+
13
+ __all__ = [
14
+ *_generated_all,
15
+ "adapter_schema",
16
+ "attributes_schema",
17
+ "conformance_vectors",
18
+ "content_kind",
19
+ "is_content_key",
20
+ ]
21
+
22
+ _MATCHERS: Final[tuple[tuple[re.Pattern[str], ContentKind], ...]] = tuple(
23
+ (re.compile(c.regex), c.kind) for d in DIALECTS for c in d.content
24
+ )
25
+
26
+
27
+ def attributes_schema() -> Traversable:
28
+ """Path to the JSON Schema of a span's `attributes` object."""
29
+ return files(__package__).joinpath("schema", "ctxflow-attributes.schema.json")
30
+
31
+
32
+ def adapter_schema() -> Traversable:
33
+ """Path to the JSON Schema of a declarative index adapter."""
34
+ return files(__package__).joinpath("schema", "adapter.schema.json")
35
+
36
+
37
+ def conformance_vectors(name: str) -> Traversable:
38
+ """Path to a conformance vector file (config, identity, text hash, ...)."""
39
+ return files(__package__).joinpath("conformance", name)
40
+
41
+
42
+ @lru_cache(maxsize=4096)
43
+ def content_kind(key: str) -> ContentKind | None:
44
+ """`drop` if a drop pattern of any dialect matches the key, else `filter`, else `None`."""
45
+ kinds = {kind for rx, kind in _MATCHERS if rx.fullmatch(key)}
46
+ if "drop" in kinds:
47
+ return "drop"
48
+ return "filter" if "filter" in kinds else None
49
+
50
+
51
+ def is_content_key(key: str) -> bool:
52
+ """True if the key carries content in any dialect (`drop` or `filter`)."""
53
+ return content_kind(key) is not None