jararaca 0.3.22__py3-none-any.whl → 0.3.24__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 jararaca might be problematic. Click here for more details.

@@ -9,6 +9,7 @@ from typing import (
9
9
  Callable,
10
10
  ContextManager,
11
11
  Generator,
12
+ Literal,
12
13
  Mapping,
13
14
  Protocol,
14
15
  Sequence,
@@ -36,10 +37,25 @@ AttributeMap = Mapping[str, AttributeValue]
36
37
 
37
38
  class TracingContextProvider(Protocol):
38
39
 
39
- def __call__(
40
+ def start_trace_context(
40
41
  self, trace_name: str, context_attributes: AttributeMap | None
41
42
  ) -> ContextManager[Any]: ...
42
43
 
44
+ def add_event(
45
+ self,
46
+ event_name: str,
47
+ event_attributes: AttributeMap | None = None,
48
+ ) -> None: ...
49
+
50
+ def set_span_status(self, status_code: Literal["OK", "ERROR", "UNSET"]) -> None: ...
51
+
52
+ def record_exception(
53
+ self,
54
+ exception: Exception,
55
+ attributes: AttributeMap | None = None,
56
+ escaped: bool = False,
57
+ ) -> None: ...
58
+
43
59
 
44
60
  class TracingContextProviderFactory(Protocol):
45
61
 
@@ -101,7 +117,7 @@ class TracedFunc:
101
117
  ) -> Any:
102
118
 
103
119
  if ctx_provider := get_tracing_ctx_provider():
104
- with ctx_provider(
120
+ with ctx_provider.start_trace_context(
105
121
  self.trace_name,
106
122
  self.trace_mapper(*args, **kwargs),
107
123
  ):
@@ -1,7 +1,11 @@
1
1
  from contextlib import contextmanager
2
- from typing import Any, Generator
2
+ from typing import Any, Generator, Literal
3
3
 
4
- from jararaca.observability.decorators import AttributeMap, get_tracing_ctx_provider
4
+ from jararaca.observability.decorators import (
5
+ AttributeMap,
6
+ TracingContextProvider,
7
+ get_tracing_ctx_provider,
8
+ )
5
9
 
6
10
 
7
11
  @contextmanager
@@ -11,10 +15,45 @@ def spawn_trace(
11
15
  ) -> Generator[None, Any, None]:
12
16
 
13
17
  if trace_context_provider := get_tracing_ctx_provider():
14
- with trace_context_provider(trace_name=name, context_attributes=attributes):
18
+ with trace_context_provider.start_trace_context(
19
+ trace_name=name, context_attributes=attributes
20
+ ):
15
21
  yield
16
22
  else:
17
23
  yield
18
24
 
19
25
 
20
- spawn_trace
26
+ def add_event(
27
+ name: str,
28
+ attributes: AttributeMap | None = None,
29
+ ) -> None:
30
+
31
+ if trace_context_provider := get_tracing_ctx_provider():
32
+ trace_context_provider.add_event(
33
+ event_name=name,
34
+ event_attributes=attributes,
35
+ )
36
+
37
+
38
+ def set_span_status(status_code: Literal["OK", "ERROR", "UNSET"]) -> None:
39
+
40
+ if trace_context_provider := get_tracing_ctx_provider():
41
+ trace_context_provider.set_span_status(status_code=status_code)
42
+
43
+
44
+ def record_exception(
45
+ exception: Exception,
46
+ attributes: AttributeMap | None = None,
47
+ escaped: bool = False,
48
+ ) -> None:
49
+
50
+ if trace_context_provider := get_tracing_ctx_provider():
51
+ trace_context_provider.record_exception(
52
+ exception=exception,
53
+ attributes=attributes,
54
+ escaped=escaped,
55
+ )
56
+
57
+
58
+ def get_tracing_provider() -> TracingContextProvider | None:
59
+ return get_tracing_ctx_provider()
@@ -1,6 +1,6 @@
1
1
  import logging
2
2
  from contextlib import asynccontextmanager, contextmanager
3
- from typing import Any, AsyncGenerator, Generator, Protocol
3
+ from typing import Any, AsyncGenerator, Generator, Literal, Protocol
4
4
 
5
5
  from opentelemetry import metrics, trace
6
6
  from opentelemetry._logs import set_logger_provider
@@ -50,7 +50,7 @@ class OtelTracingContextProvider(TracingContextProvider):
50
50
  self.app_context = app_context
51
51
 
52
52
  @contextmanager
53
- def __call__(
53
+ def start_trace_context(
54
54
  self,
55
55
  trace_name: str,
56
56
  context_attributes: AttributeMap | None,
@@ -59,6 +59,29 @@ class OtelTracingContextProvider(TracingContextProvider):
59
59
  with tracer.start_as_current_span(trace_name, attributes=context_attributes):
60
60
  yield
61
61
 
62
+ def add_event(
63
+ self, event_name: str, event_attributes: AttributeMap | None = None
64
+ ) -> None:
65
+ trace.get_current_span().add_event(name=event_name, attributes=event_attributes)
66
+
67
+ def set_span_status(self, status_code: Literal["OK", "ERROR", "UNSET"]) -> None:
68
+ span = trace.get_current_span()
69
+ if status_code == "OK":
70
+ span.set_status(trace.Status(trace.StatusCode.OK))
71
+ elif status_code == "ERROR":
72
+ span.set_status(trace.Status(trace.StatusCode.ERROR))
73
+ else:
74
+ span.set_status(trace.Status(trace.StatusCode.UNSET))
75
+
76
+ def record_exception(
77
+ self,
78
+ exception: Exception,
79
+ attributes: AttributeMap | None = None,
80
+ escaped: bool = False,
81
+ ) -> None:
82
+ span = trace.get_current_span()
83
+ span.record_exception(exception, attributes=attributes, escaped=escaped)
84
+
62
85
 
63
86
  class OtelTracingContextProviderFactory(TracingContextProviderFactory):
64
87
 
@@ -101,6 +124,12 @@ class OtelTracingContextProviderFactory(TracingContextProviderFactory):
101
124
  f"http.request.header.{k}": v
102
125
  for k, v in tx_data.request.headers.items()
103
126
  },
127
+ "http.request.body": (await tx_data.request.body())[:5000].decode(
128
+ errors="ignore"
129
+ ),
130
+ "http.request.client.host": (
131
+ tx_data.request.client.host if tx_data.request.client else ""
132
+ ),
104
133
  }
105
134
 
106
135
  elif tx_data.context_type == "message_bus":
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: jararaca
3
- Version: 0.3.22
3
+ Version: 0.3.24
4
4
  Summary: A simple and fast API framework for Python
5
5
  Home-page: https://github.com/LuscasLeo/jararaca
6
6
  Author: Lucas S
@@ -1,6 +1,6 @@
1
1
  LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
2
2
  README.md,sha256=YmCngjU8llW0l7L3tuXkkfr8qH7V9aBMgfp2jEzeiKg,3517
3
- pyproject.toml,sha256=cIaZ30kR0_7WQwX6DOqoxWOKZrZ71y8bIh81lS5SYyg,2739
3
+ pyproject.toml,sha256=6sYLrOMmNeyU9uwMy6ye483fbPxeNvmrL39AVtHUMcI,2739
4
4
  jararaca/__init__.py,sha256=niZQiN-Whyw2ExcwQbB8uBDPy90pK36pPwa7dYkecuU,22822
5
5
  jararaca/__main__.py,sha256=-O3vsB5lHdqNFjUtoELDF81IYFtR-DSiiFMzRaiSsv4,67
6
6
  jararaca/broker_backend/__init__.py,sha256=GzEIuHR1xzgCJD4FE3harNjoaYzxHMHoEL0_clUaC-k,3528
@@ -26,11 +26,11 @@ jararaca/messagebus/message.py,sha256=U6cyd2XknX8mtm0333slz5fanky2PFLWCmokAO56vv
26
26
  jararaca/messagebus/publisher.py,sha256=JTkxdKbvxvDWT8nK8PVEyyX061vYYbKQMxRHXrZtcEY,2173
27
27
  jararaca/messagebus/worker.py,sha256=DiKDUhcU4rEjjA_3KqCmnN3X5yyokZq_-SbLryjS_PM,69237
28
28
  jararaca/microservice.py,sha256=DW4RVeqgrx4J-dAg17sbzTn_sLXuvV1UOQFde2fpqds,11471
29
- jararaca/observability/decorators.py,sha256=vKAPGLyKz092rd1K4k3xtI2FrRafN69EEuRZKEhaLSk,5627
30
- jararaca/observability/hooks.py,sha256=VRYg-vlNlFxu9FqOgxyS9VIY6zDcCcgOuZ0RhTUtjwY,488
29
+ jararaca/observability/decorators.py,sha256=xTt4HEmpm_m1OUS29kaoZLMCT2YYToJUzQziepl8qfQ,6062
30
+ jararaca/observability/hooks.py,sha256=vQCxb5m4uFse0lJIAuzSd84acu7iGDNgf4kpaWYkju8,1499
31
31
  jararaca/observability/interceptor.py,sha256=U4ZLM0f8j6Q7gMUKKnA85bnvD-Qa0ii79Qa_X8KsXAQ,1498
32
32
  jararaca/observability/providers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
33
- jararaca/observability/providers/otel.py,sha256=LgkDRLRFA689ypfVjR67EU-eFHYBZRU01npDs-K8HMQ,9613
33
+ jararaca/observability/providers/otel.py,sha256=DCNjGhcpF-XdlGTiYoQg9F_1ftcggTItDfJ_PjlZm0s,10808
34
34
  jararaca/persistence/base.py,sha256=xnGUbsLNz3gO-9iJt-Sn5NY13Yc9-misP8wLwQuGGoM,1024
35
35
  jararaca/persistence/exports.py,sha256=Ghx4yoFaB4QVTb9WxrFYgmcSATXMNvrOvT8ybPNKXCA,62
36
36
  jararaca/persistence/interceptors/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -76,8 +76,8 @@ jararaca/tools/typescript/interface_parser.py,sha256=yOSuOXKOeG0soGFo0fKiZIabu4Y
76
76
  jararaca/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
77
77
  jararaca/utils/rabbitmq_utils.py,sha256=ytdAFUyv-OBkaVnxezuJaJoLrmN7giZgtKeet_IsMBs,10918
78
78
  jararaca/utils/retry.py,sha256=DzPX_fXUvTqej6BQ8Mt2dvLo9nNlTBm7Kx2pFZ26P2Q,4668
79
- jararaca-0.3.22.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
80
- jararaca-0.3.22.dist-info/METADATA,sha256=--9VrDmq9co0M_0CDIcr_GjlbwhmHKypO4dh5F4sZYQ,5149
81
- jararaca-0.3.22.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
82
- jararaca-0.3.22.dist-info/entry_points.txt,sha256=WIh3aIvz8LwUJZIDfs4EeH3VoFyCGEk7cWJurW38q0I,45
83
- jararaca-0.3.22.dist-info/RECORD,,
79
+ jararaca-0.3.24.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
80
+ jararaca-0.3.24.dist-info/METADATA,sha256=uNJ8D0EW1oyL0t2bIodsYE3nVXnr8R6oJGTUc_uXOVw,5149
81
+ jararaca-0.3.24.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
82
+ jararaca-0.3.24.dist-info/entry_points.txt,sha256=WIh3aIvz8LwUJZIDfs4EeH3VoFyCGEk7cWJurW38q0I,45
83
+ jararaca-0.3.24.dist-info/RECORD,,
pyproject.toml CHANGED
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "jararaca"
3
- version = "0.3.22"
3
+ version = "0.3.24"
4
4
  description = "A simple and fast API framework for Python"
5
5
  authors = ["Lucas S <me@luscasleo.dev>"]
6
6
  readme = "README.md"