fastapi-factory-utilities 0.2.11__py3-none-any.whl → 0.2.12__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 fastapi-factory-utilities might be problematic. Click here for more details.
- fastapi_factory_utilities/core/plugins/odm_plugin/repositories.py +2 -3
- fastapi_factory_utilities/core/plugins/opentelemetry_plugin/builder.py +65 -16
- fastapi_factory_utilities/core/plugins/opentelemetry_plugin/configs.py +13 -0
- {fastapi_factory_utilities-0.2.11.dist-info → fastapi_factory_utilities-0.2.12.dist-info}/METADATA +1 -1
- {fastapi_factory_utilities-0.2.11.dist-info → fastapi_factory_utilities-0.2.12.dist-info}/RECORD +8 -8
- {fastapi_factory_utilities-0.2.11.dist-info → fastapi_factory_utilities-0.2.12.dist-info}/LICENSE +0 -0
- {fastapi_factory_utilities-0.2.11.dist-info → fastapi_factory_utilities-0.2.12.dist-info}/WHEEL +0 -0
- {fastapi_factory_utilities-0.2.11.dist-info → fastapi_factory_utilities-0.2.12.dist-info}/entry_points.txt +0 -0
|
@@ -6,7 +6,6 @@ from collections.abc import AsyncGenerator, Callable
|
|
|
6
6
|
from contextlib import asynccontextmanager
|
|
7
7
|
from typing import Any, Generic, TypeVar, get_args
|
|
8
8
|
from uuid import UUID
|
|
9
|
-
from venv import create
|
|
10
9
|
|
|
11
10
|
from motor.motor_asyncio import AsyncIOMotorClientSession, AsyncIOMotorDatabase
|
|
12
11
|
from pydantic import BaseModel
|
|
@@ -79,7 +78,7 @@ class AbstractRepository(ABC, Generic[DocumentGenericType, EntityGenericType]):
|
|
|
79
78
|
UnableToCreateEntityDueToDuplicateKeyError: If the entity cannot be created due to a duplicate key error.
|
|
80
79
|
OperationError: If the operation fails.
|
|
81
80
|
"""
|
|
82
|
-
insert_time: datetime.datetime = datetime.datetime.now(tz=datetime.
|
|
81
|
+
insert_time: datetime.datetime = datetime.datetime.now(tz=datetime.UTC)
|
|
83
82
|
try:
|
|
84
83
|
entity_dump: dict[str, Any] = entity.model_dump()
|
|
85
84
|
entity_dump["created_at"] = insert_time
|
|
@@ -120,7 +119,7 @@ class AbstractRepository(ABC, Generic[DocumentGenericType, EntityGenericType]):
|
|
|
120
119
|
ValueError: If the entity cannot be created from the document.
|
|
121
120
|
OperationError: If the operation fails.
|
|
122
121
|
"""
|
|
123
|
-
update_time: datetime.datetime = datetime.datetime.now(tz=datetime.
|
|
122
|
+
update_time: datetime.datetime = datetime.datetime.now(tz=datetime.UTC)
|
|
124
123
|
try:
|
|
125
124
|
entity_dump: dict[str, Any] = entity.model_dump()
|
|
126
125
|
entity_dump["updated_at"] = update_time
|
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
"""Provides a factory function to build a objets for OpenTelemetry."""
|
|
2
2
|
|
|
3
3
|
from typing import Any, Self
|
|
4
|
+
from urllib.parse import ParseResult, urlparse
|
|
4
5
|
|
|
5
|
-
from opentelemetry.exporter.otlp.proto.grpc.metric_exporter import
|
|
6
|
-
|
|
6
|
+
from opentelemetry.exporter.otlp.proto.grpc.metric_exporter import (
|
|
7
|
+
OTLPMetricExporter as OTLPMetricExporterGRPC,
|
|
8
|
+
)
|
|
9
|
+
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import (
|
|
10
|
+
OTLPSpanExporter as OTLPSpanExporterGRPC,
|
|
11
|
+
)
|
|
12
|
+
from opentelemetry.exporter.otlp.proto.http.metric_exporter import (
|
|
13
|
+
OTLPMetricExporter as OTLPMetricExporterHTTP,
|
|
14
|
+
)
|
|
15
|
+
from opentelemetry.exporter.otlp.proto.http.trace_exporter import (
|
|
16
|
+
OTLPSpanExporter as OTLPSpanExporterHTTP,
|
|
17
|
+
)
|
|
7
18
|
from opentelemetry.metrics import set_meter_provider
|
|
8
19
|
from opentelemetry.propagate import set_global_textmap
|
|
9
20
|
from opentelemetry.propagators.b3 import B3MultiFormat
|
|
@@ -31,24 +42,30 @@ from fastapi_factory_utilities.core.utils.yaml_reader import (
|
|
|
31
42
|
YamlFileReader,
|
|
32
43
|
)
|
|
33
44
|
|
|
34
|
-
from .configs import OpenTelemetryConfig
|
|
45
|
+
from .configs import OpenTelemetryConfig, ProtocolEnum
|
|
35
46
|
from .exceptions import OpenTelemetryPluginConfigError
|
|
36
47
|
|
|
48
|
+
GRPC_PORT: int = 4317
|
|
49
|
+
HTTP_PORT: int = 4318
|
|
50
|
+
|
|
37
51
|
|
|
38
52
|
class OpenTelemetryPluginBuilder:
|
|
39
53
|
"""Configure the injection bindings for OpenTelemetryPlugin."""
|
|
40
54
|
|
|
41
|
-
def __init__(self, application: ApplicationAbstractProtocol) -> None:
|
|
55
|
+
def __init__(self, application: ApplicationAbstractProtocol, settings: OpenTelemetryConfig | None = None) -> None:
|
|
42
56
|
"""Instantiate the OpenTelemetryPluginFactory.
|
|
43
57
|
|
|
44
58
|
Args:
|
|
45
59
|
application (BaseApplicationProtocol): The application object.
|
|
60
|
+
settings (OpenTelemetryConfig | None): The OpenTelemetry configuration object.
|
|
46
61
|
"""
|
|
47
62
|
self._application: ApplicationAbstractProtocol = application
|
|
48
63
|
self._resource: Resource | None = None
|
|
49
|
-
self._config: OpenTelemetryConfig | None =
|
|
64
|
+
self._config: OpenTelemetryConfig | None = settings
|
|
50
65
|
self._meter_provider: MeterProvider | None = None
|
|
51
66
|
self._tracer_provider: TracerProvider | None = None
|
|
67
|
+
self._trace_exporter: OTLPSpanExporterGRPC | OTLPSpanExporterHTTP | None = None
|
|
68
|
+
self._metric_exporter: OTLPMetricExporterGRPC | OTLPMetricExporterHTTP | None = None
|
|
52
69
|
|
|
53
70
|
@property
|
|
54
71
|
def resource(self) -> Resource | None:
|
|
@@ -161,12 +178,27 @@ class OpenTelemetryPluginBuilder:
|
|
|
161
178
|
|
|
162
179
|
# TODO: Extract to a dedicated method for the exporter and period reader setup
|
|
163
180
|
|
|
181
|
+
url_parsed: ParseResult = urlparse(self._config.endpoint.unicode_string())
|
|
182
|
+
|
|
183
|
+
exporter: OTLPMetricExporterGRPC | OTLPMetricExporterHTTP
|
|
164
184
|
# Setup the Exporter
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
185
|
+
if url_parsed.port == GRPC_PORT or self._config.protocol == ProtocolEnum.OTLP_GRPC:
|
|
186
|
+
exporter = OTLPMetricExporterGRPC(
|
|
187
|
+
endpoint=f"{self._config.endpoint.unicode_string()}",
|
|
188
|
+
timeout=self._config.timeout,
|
|
189
|
+
insecure=True if str(self._config.endpoint).startswith("http") else False,
|
|
190
|
+
)
|
|
191
|
+
elif url_parsed.port == HTTP_PORT or self._config.protocol == ProtocolEnum.OTLP_HTTP:
|
|
192
|
+
exporter = OTLPMetricExporterHTTP(
|
|
193
|
+
endpoint=f"{self._config.endpoint.unicode_string()}/v1/metrics",
|
|
194
|
+
timeout=self._config.timeout,
|
|
195
|
+
)
|
|
196
|
+
else:
|
|
197
|
+
raise OpenTelemetryPluginConfigError(
|
|
198
|
+
"The endpoint port is not supported. Use 4317 for gRPC or 4318 for HTTP or set the protocol."
|
|
199
|
+
)
|
|
200
|
+
|
|
201
|
+
self._metric_exporter = exporter
|
|
170
202
|
|
|
171
203
|
# Setup the Metric Reader
|
|
172
204
|
meter_config: OpenTelemetryMeterConfig = self._config.meter_config
|
|
@@ -214,12 +246,28 @@ class OpenTelemetryPluginBuilder:
|
|
|
214
246
|
if self._config.tracer_config is None:
|
|
215
247
|
raise OpenTelemetryPluginConfigError("The tracer configuration is missing.")
|
|
216
248
|
|
|
249
|
+
exporter: OTLPSpanExporterGRPC | OTLPSpanExporterHTTP
|
|
250
|
+
url_parsed: ParseResult = urlparse(self._config.endpoint.unicode_string())
|
|
217
251
|
# Setup the Exporter
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
252
|
+
if url_parsed.port == GRPC_PORT or self._config.protocol == ProtocolEnum.OTLP_GRPC:
|
|
253
|
+
insecure: bool = False if str(self._config.endpoint).startswith("https") else True
|
|
254
|
+
endpoint: str = f"{self._config.endpoint.unicode_string()}"
|
|
255
|
+
exporter = OTLPSpanExporterGRPC(
|
|
256
|
+
endpoint=endpoint,
|
|
257
|
+
# timeout=self._config.timeout,
|
|
258
|
+
insecure=insecure,
|
|
259
|
+
)
|
|
260
|
+
elif url_parsed.port == HTTP_PORT or self._config.protocol == ProtocolEnum.OTLP_HTTP:
|
|
261
|
+
exporter = OTLPSpanExporterHTTP(
|
|
262
|
+
endpoint=f"{self._config.endpoint.unicode_string()}/v1/traces",
|
|
263
|
+
# timeout=self._config.timeout,
|
|
264
|
+
)
|
|
265
|
+
else:
|
|
266
|
+
raise OpenTelemetryPluginConfigError(
|
|
267
|
+
"The endpoint port is not supported. Use 4317 for gRPC or 4318 for HTTP or set the protocol."
|
|
268
|
+
)
|
|
269
|
+
|
|
270
|
+
self._trace_exporter = exporter
|
|
223
271
|
|
|
224
272
|
# Setup the Span Processor
|
|
225
273
|
tracer_config: OpenTelemetryTracerConfig = self._config.tracer_config
|
|
@@ -261,7 +309,8 @@ class OpenTelemetryPluginBuilder:
|
|
|
261
309
|
Self: The OpenTelemetryPluginFactory object.
|
|
262
310
|
"""
|
|
263
311
|
self.build_resource()
|
|
264
|
-
self.
|
|
312
|
+
if self._config is None:
|
|
313
|
+
self.build_config()
|
|
265
314
|
self.build_meter_provider()
|
|
266
315
|
self.build_tracer_provider()
|
|
267
316
|
|
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
"""Provides the configuration model for the OpenTelemetry plugin."""
|
|
2
2
|
|
|
3
|
+
from enum import StrEnum
|
|
3
4
|
from typing import Annotated
|
|
4
5
|
|
|
5
6
|
from pydantic import BaseModel, ConfigDict, Field, UrlConstraints
|
|
6
7
|
from pydantic_core import Url
|
|
7
8
|
|
|
8
9
|
|
|
10
|
+
class ProtocolEnum(StrEnum):
|
|
11
|
+
"""Defines the protocol enum for OpenTelemetry."""
|
|
12
|
+
|
|
13
|
+
OTLP_GRPC = "otlp_grpc"
|
|
14
|
+
OTLP_HTTP = "otlp_http"
|
|
15
|
+
|
|
16
|
+
|
|
9
17
|
class OpenTelemetryMeterConfig(BaseModel):
|
|
10
18
|
"""Provides the configuration model for the OpenTelemetry meter as sub-model."""
|
|
11
19
|
|
|
@@ -77,6 +85,11 @@ class OpenTelemetryConfig(BaseModel):
|
|
|
77
85
|
description="The collector endpoint.",
|
|
78
86
|
)
|
|
79
87
|
|
|
88
|
+
protocol: ProtocolEnum | None = Field(
|
|
89
|
+
default=None,
|
|
90
|
+
description="The protocol to use for the collector.",
|
|
91
|
+
)
|
|
92
|
+
|
|
80
93
|
timeout: int = Field(
|
|
81
94
|
default=TEN_SECONDS_IN_SECONDS,
|
|
82
95
|
description="The timeout in seconds for the collector.",
|
{fastapi_factory_utilities-0.2.11.dist-info → fastapi_factory_utilities-0.2.12.dist-info}/METADATA
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: fastapi_factory_utilities
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.12
|
|
4
4
|
Summary: Consolidate libraries and utilities to create microservices in Python with FastAPI, Beanie, Httpx, AioPika and OpenTelemetry.
|
|
5
5
|
License: MIT
|
|
6
6
|
Keywords: python,fastapi,beanie,httpx,opentelemetry,microservices
|
{fastapi_factory_utilities-0.2.11.dist-info → fastapi_factory_utilities-0.2.12.dist-info}/RECORD
RENAMED
|
@@ -25,10 +25,10 @@ fastapi_factory_utilities/core/plugins/odm_plugin/configs.py,sha256=zQoJC1wLNyq2
|
|
|
25
25
|
fastapi_factory_utilities/core/plugins/odm_plugin/depends.py,sha256=OcLsfTLzMBk_xFV6qsMy_-qFkiphEbbEuaHUooagxg8,730
|
|
26
26
|
fastapi_factory_utilities/core/plugins/odm_plugin/documents.py,sha256=BFQYHxHBmTacJRfhZi2OffvT_RAFvAAiDVQAa_d6Y7w,1141
|
|
27
27
|
fastapi_factory_utilities/core/plugins/odm_plugin/exceptions.py,sha256=acnKJB0lGAzDs-7-LjBap8shjP3iV1a7dw7ouPVF27o,551
|
|
28
|
-
fastapi_factory_utilities/core/plugins/odm_plugin/repositories.py,sha256=
|
|
28
|
+
fastapi_factory_utilities/core/plugins/odm_plugin/repositories.py,sha256=r880o--iVj3oK3yTenM5kgJwfFWKSUZa0bfnEwOukFE,8705
|
|
29
29
|
fastapi_factory_utilities/core/plugins/opentelemetry_plugin/__init__.py,sha256=UsXPjiAASn5GIHW8vrF32mklxGNq8ajILV-ty4K1Tbs,4371
|
|
30
|
-
fastapi_factory_utilities/core/plugins/opentelemetry_plugin/builder.py,sha256=
|
|
31
|
-
fastapi_factory_utilities/core/plugins/opentelemetry_plugin/configs.py,sha256=
|
|
30
|
+
fastapi_factory_utilities/core/plugins/opentelemetry_plugin/builder.py,sha256=9npQImifYAbEg0lFG7KwZ8V78SNrPoaINgd8vKitdMw,12509
|
|
31
|
+
fastapi_factory_utilities/core/plugins/opentelemetry_plugin/configs.py,sha256=pMG9leMB7rtdkdGFLIxXflV7bf9epGrrYPt2N97KZcM,3750
|
|
32
32
|
fastapi_factory_utilities/core/plugins/opentelemetry_plugin/exceptions.py,sha256=CpsHayfQpP0zghN8y5PP6TBy-cXhHoNxBR--I86gAdE,327
|
|
33
33
|
fastapi_factory_utilities/core/plugins/opentelemetry_plugin/helpers.py,sha256=qpTIzX67orJz7vy6SBIwRs24omMBoToJkhpurZRjPuk,1533
|
|
34
34
|
fastapi_factory_utilities/core/protocols.py,sha256=TzZKr_KfmTphk2LL-TD2XzxNlLbihbGM2DxWMhc5lEQ,2428
|
|
@@ -64,8 +64,8 @@ fastapi_factory_utilities/example/models/books/repository.py,sha256=7K63uAsSEGZ2
|
|
|
64
64
|
fastapi_factory_utilities/example/services/books/__init__.py,sha256=Z06yNRoA7Zg3TGN-Q9rrvJg6Bbx-qJw661MVwukV6vQ,148
|
|
65
65
|
fastapi_factory_utilities/example/services/books/services.py,sha256=-x7d4hotUWLzWo5uImMjFmtNcSTHwWv2bfttIbYYKbA,5380
|
|
66
66
|
fastapi_factory_utilities/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
67
|
-
fastapi_factory_utilities-0.2.
|
|
68
|
-
fastapi_factory_utilities-0.2.
|
|
69
|
-
fastapi_factory_utilities-0.2.
|
|
70
|
-
fastapi_factory_utilities-0.2.
|
|
71
|
-
fastapi_factory_utilities-0.2.
|
|
67
|
+
fastapi_factory_utilities-0.2.12.dist-info/LICENSE,sha256=iO1nLzMMst6vEiqgSUrfrbetM7b0bvdzXhbed5tqG8o,1074
|
|
68
|
+
fastapi_factory_utilities-0.2.12.dist-info/METADATA,sha256=1h_N321DsWiApHV0OZs9sRpo78nmxyD61x6-x80AJ00,3387
|
|
69
|
+
fastapi_factory_utilities-0.2.12.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
|
|
70
|
+
fastapi_factory_utilities-0.2.12.dist-info/entry_points.txt,sha256=IK0VcBexXo4uXQmTrbfhhnnfq4GmXPRn0GBB8hzlsq4,101
|
|
71
|
+
fastapi_factory_utilities-0.2.12.dist-info/RECORD,,
|
{fastapi_factory_utilities-0.2.11.dist-info → fastapi_factory_utilities-0.2.12.dist-info}/LICENSE
RENAMED
|
File without changes
|
{fastapi_factory_utilities-0.2.11.dist-info → fastapi_factory_utilities-0.2.12.dist-info}/WHEEL
RENAMED
|
File without changes
|
|
File without changes
|