aws-durable-execution-sdk-python-telemetry-exporter 0.0.1__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.
- aws_durable_execution_sdk_python_telemetry_exporter/LICENSE +175 -0
- aws_durable_execution_sdk_python_telemetry_exporter/NOTICE +1 -0
- aws_durable_execution_sdk_python_telemetry_exporter/__about__.py +4 -0
- aws_durable_execution_sdk_python_telemetry_exporter/__init__.py +90 -0
- aws_durable_execution_sdk_python_telemetry_exporter/_export_scheduler.py +178 -0
- aws_durable_execution_sdk_python_telemetry_exporter/exporters/__init__.py +86 -0
- aws_durable_execution_sdk_python_telemetry_exporter/exporters/_common.py +109 -0
- aws_durable_execution_sdk_python_telemetry_exporter/exporters/aurora_exporter.py +152 -0
- aws_durable_execution_sdk_python_telemetry_exporter/exporters/cloudwatch_logs_exporter.py +96 -0
- aws_durable_execution_sdk_python_telemetry_exporter/exporters/dynamodb_exporter.py +75 -0
- aws_durable_execution_sdk_python_telemetry_exporter/exporters/eventbridge_exporter.py +82 -0
- aws_durable_execution_sdk_python_telemetry_exporter/exporters/file_exporter.py +88 -0
- aws_durable_execution_sdk_python_telemetry_exporter/exporters/firehose_exporter.py +63 -0
- aws_durable_execution_sdk_python_telemetry_exporter/exporters/http_exporter.py +82 -0
- aws_durable_execution_sdk_python_telemetry_exporter/exporters/lambda_log_exporter.py +41 -0
- aws_durable_execution_sdk_python_telemetry_exporter/exporters/opensearch_exporter.py +109 -0
- aws_durable_execution_sdk_python_telemetry_exporter/exporters/otel_exporter.py +151 -0
- aws_durable_execution_sdk_python_telemetry_exporter/exporters/redshift_exporter.py +155 -0
- aws_durable_execution_sdk_python_telemetry_exporter/exporters/s3_exporter.py +105 -0
- aws_durable_execution_sdk_python_telemetry_exporter/exporters/sqs_exporter.py +96 -0
- aws_durable_execution_sdk_python_telemetry_exporter/operations_index.py +132 -0
- aws_durable_execution_sdk_python_telemetry_exporter/plugin.py +452 -0
- aws_durable_execution_sdk_python_telemetry_exporter/py.typed +0 -0
- aws_durable_execution_sdk_python_telemetry_exporter/truncation.py +107 -0
- aws_durable_execution_sdk_python_telemetry_exporter/types.py +127 -0
- aws_durable_execution_sdk_python_telemetry_exporter-0.0.1.dist-info/METADATA +256 -0
- aws_durable_execution_sdk_python_telemetry_exporter-0.0.1.dist-info/RECORD +28 -0
- aws_durable_execution_sdk_python_telemetry_exporter-0.0.1.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026-present Amazon.com, Inc. or its affiliates.
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
"""Durable Execution Telemetry instrumentation plugin.
|
|
5
|
+
|
|
6
|
+
Instruments the AWS Durable Execution Python SDK.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from aws_durable_execution_sdk_python_telemetry_exporter.__about__ import __version__
|
|
10
|
+
from aws_durable_execution_sdk_python_telemetry_exporter.exporters import (
|
|
11
|
+
AuroraEngine,
|
|
12
|
+
AuroraExporter,
|
|
13
|
+
CloudWatchLogsExporter,
|
|
14
|
+
DynamoDBExporter,
|
|
15
|
+
EventBridgeExporter,
|
|
16
|
+
FileExporter,
|
|
17
|
+
FileMode,
|
|
18
|
+
FirehoseExporter,
|
|
19
|
+
HttpExporter,
|
|
20
|
+
HttpMethod,
|
|
21
|
+
LambdaLogExporter,
|
|
22
|
+
OpenSearchAuth,
|
|
23
|
+
OpenSearchExporter,
|
|
24
|
+
OTelExporter,
|
|
25
|
+
OTelProtocol,
|
|
26
|
+
RedshiftExporter,
|
|
27
|
+
S3Exporter,
|
|
28
|
+
S3Partitioning,
|
|
29
|
+
SQSExporter,
|
|
30
|
+
)
|
|
31
|
+
from aws_durable_execution_sdk_python_telemetry_exporter.operations_index import (
|
|
32
|
+
OperationsFormat,
|
|
33
|
+
apply_operations_format,
|
|
34
|
+
build_operations_by_name,
|
|
35
|
+
with_operations_by_name,
|
|
36
|
+
)
|
|
37
|
+
from aws_durable_execution_sdk_python_telemetry_exporter.plugin import (
|
|
38
|
+
DurableExecutionTelemetryPlugin,
|
|
39
|
+
durable_execution_telemetry,
|
|
40
|
+
)
|
|
41
|
+
from aws_durable_execution_sdk_python_telemetry_exporter.truncation import (
|
|
42
|
+
truncate_record,
|
|
43
|
+
)
|
|
44
|
+
from aws_durable_execution_sdk_python_telemetry_exporter.types import (
|
|
45
|
+
ContentConfig,
|
|
46
|
+
ContentOperations,
|
|
47
|
+
EmitMode,
|
|
48
|
+
TelemetryExporter,
|
|
49
|
+
OperationDetail,
|
|
50
|
+
OperationOverride,
|
|
51
|
+
DurableExecutionTelemetryConfig,
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
__all__ = [
|
|
56
|
+
"__version__",
|
|
57
|
+
"AuroraEngine",
|
|
58
|
+
"AuroraExporter",
|
|
59
|
+
"CloudWatchLogsExporter",
|
|
60
|
+
"ContentConfig",
|
|
61
|
+
"ContentOperations",
|
|
62
|
+
"DynamoDBExporter",
|
|
63
|
+
"EmitMode",
|
|
64
|
+
"EventBridgeExporter",
|
|
65
|
+
"FileExporter",
|
|
66
|
+
"FileMode",
|
|
67
|
+
"FirehoseExporter",
|
|
68
|
+
"HttpExporter",
|
|
69
|
+
"HttpMethod",
|
|
70
|
+
"TelemetryExporter",
|
|
71
|
+
"LambdaLogExporter",
|
|
72
|
+
"OTelExporter",
|
|
73
|
+
"OTelProtocol",
|
|
74
|
+
"OpenSearchAuth",
|
|
75
|
+
"OpenSearchExporter",
|
|
76
|
+
"OperationDetail",
|
|
77
|
+
"OperationOverride",
|
|
78
|
+
"OperationsFormat",
|
|
79
|
+
"RedshiftExporter",
|
|
80
|
+
"S3Exporter",
|
|
81
|
+
"S3Partitioning",
|
|
82
|
+
"SQSExporter",
|
|
83
|
+
"DurableExecutionTelemetryConfig",
|
|
84
|
+
"DurableExecutionTelemetryPlugin",
|
|
85
|
+
"apply_operations_format",
|
|
86
|
+
"build_operations_by_name",
|
|
87
|
+
"truncate_record",
|
|
88
|
+
"with_operations_by_name",
|
|
89
|
+
"durable_execution_telemetry",
|
|
90
|
+
]
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026-present Amazon.com, Inc. or its affiliates.
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
"""Latest-pending asynchronous export scheduling for Durable Execution Telemetry."""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
import logging
|
|
9
|
+
import threading
|
|
10
|
+
from typing import Any
|
|
11
|
+
|
|
12
|
+
from aws_durable_execution_sdk_python_telemetry_exporter.truncation import (
|
|
13
|
+
truncate_record,
|
|
14
|
+
)
|
|
15
|
+
from aws_durable_execution_sdk_python_telemetry_exporter.types import TelemetryExporter
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
_logger = logging.getLogger("aws_durable_execution_sdk_python_telemetry_exporter")
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class _ExportScheduler:
|
|
22
|
+
"""Run all exporters on one lazy worker with one pending record per execution.
|
|
23
|
+
|
|
24
|
+
The pending map is keyed by ``executionArn`` so a snapshot only ever
|
|
25
|
+
replaces its own execution's pending snapshot. Several executions may be in
|
|
26
|
+
flight on one plugin instance (the local runner drives independent
|
|
27
|
+
executions concurrently through a shared
|
|
28
|
+
``durable_execution_telemetry(...)``), and a single shared slot let
|
|
29
|
+
execution B's ``RUNNING`` snapshot displace execution A's terminal
|
|
30
|
+
snapshot before the worker claimed it.
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
def __init__(self, exporters: list[TelemetryExporter]) -> None:
|
|
34
|
+
self._exporters = exporters
|
|
35
|
+
self._condition = threading.Condition(threading.Lock())
|
|
36
|
+
# executionArn -> latest pending snapshot, in first-arrival order.
|
|
37
|
+
self._pending: dict[str, dict[str, Any]] = {}
|
|
38
|
+
self._flush_requested = False
|
|
39
|
+
self._flush_event: threading.Event | None = None
|
|
40
|
+
self._worker: threading.Thread | None = None
|
|
41
|
+
self._disabled = False
|
|
42
|
+
|
|
43
|
+
def schedule(self, record: dict[str, Any]) -> None:
|
|
44
|
+
"""Replace this execution's pending snapshot and return without exporting."""
|
|
45
|
+
displaced: dict[str, Any] | None = None
|
|
46
|
+
failed_pending: dict[str, dict[str, Any]] | None = None
|
|
47
|
+
start_error: Exception | None = None
|
|
48
|
+
arn = str(record.get("executionArn", ""))
|
|
49
|
+
with self._condition:
|
|
50
|
+
if self._disabled:
|
|
51
|
+
return
|
|
52
|
+
displaced = self._pending.get(arn)
|
|
53
|
+
# Assigning an existing key keeps its first-arrival position.
|
|
54
|
+
self._pending[arn] = record
|
|
55
|
+
failed_pending, start_error = self._ensure_worker_locked()
|
|
56
|
+
self._condition.notify()
|
|
57
|
+
# Releasing either record may run custom finalizers, so do it unlocked.
|
|
58
|
+
del displaced, failed_pending
|
|
59
|
+
if start_error is not None:
|
|
60
|
+
_logger.warning(
|
|
61
|
+
"durable-execution-telemetry: could not start export worker; disabling "
|
|
62
|
+
"asynchronous export: %s",
|
|
63
|
+
start_error,
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
def drain(self) -> None:
|
|
67
|
+
"""Wait until every pending record is exported and exporters flush."""
|
|
68
|
+
failed_pending: dict[str, dict[str, Any]] | None = None
|
|
69
|
+
start_error: Exception | None = None
|
|
70
|
+
with self._condition:
|
|
71
|
+
if self._disabled:
|
|
72
|
+
return
|
|
73
|
+
if not self._flush_requested:
|
|
74
|
+
self._flush_requested = True
|
|
75
|
+
self._flush_event = threading.Event()
|
|
76
|
+
flush_event = self._flush_event
|
|
77
|
+
assert flush_event is not None
|
|
78
|
+
failed_pending, start_error = self._ensure_worker_locked()
|
|
79
|
+
started = not self._disabled
|
|
80
|
+
self._condition.notify()
|
|
81
|
+
del failed_pending
|
|
82
|
+
if start_error is not None:
|
|
83
|
+
_logger.warning(
|
|
84
|
+
"durable-execution-telemetry: could not start export worker; disabling "
|
|
85
|
+
"asynchronous export: %s",
|
|
86
|
+
start_error,
|
|
87
|
+
)
|
|
88
|
+
if started:
|
|
89
|
+
flush_event.wait()
|
|
90
|
+
|
|
91
|
+
def _ensure_worker_locked(
|
|
92
|
+
self,
|
|
93
|
+
) -> tuple[dict[str, dict[str, Any]] | None, Exception | None]:
|
|
94
|
+
if self._worker is not None and self._worker.is_alive():
|
|
95
|
+
return None, None
|
|
96
|
+
worker = threading.Thread(
|
|
97
|
+
target=self._run,
|
|
98
|
+
name=f"durable-execution-telemetry-export-{id(self)}",
|
|
99
|
+
daemon=True,
|
|
100
|
+
)
|
|
101
|
+
self._worker = worker
|
|
102
|
+
try:
|
|
103
|
+
worker.start()
|
|
104
|
+
except Exception as exc: # noqa: BLE001 - instrumentation must not escape hooks
|
|
105
|
+
self._disabled = True
|
|
106
|
+
self._worker = None
|
|
107
|
+
failed_pending = self._pending
|
|
108
|
+
self._pending = {}
|
|
109
|
+
failed_event = self._flush_event
|
|
110
|
+
self._flush_event = None
|
|
111
|
+
self._flush_requested = False
|
|
112
|
+
if failed_event is not None:
|
|
113
|
+
failed_event.set()
|
|
114
|
+
return failed_pending, exc
|
|
115
|
+
return None, None
|
|
116
|
+
|
|
117
|
+
def _run(self) -> None:
|
|
118
|
+
while True:
|
|
119
|
+
record: dict[str, Any] | None = None
|
|
120
|
+
flush_event: threading.Event | None = None
|
|
121
|
+
with self._condition:
|
|
122
|
+
while not self._pending and not self._flush_requested:
|
|
123
|
+
self._condition.wait()
|
|
124
|
+
if self._pending:
|
|
125
|
+
# Export every pending execution before honoring a flush, so
|
|
126
|
+
# drain() means everything scheduled so far was delivered.
|
|
127
|
+
arn = next(iter(self._pending))
|
|
128
|
+
record = self._pending.pop(arn)
|
|
129
|
+
else:
|
|
130
|
+
flush_event = self._flush_event
|
|
131
|
+
self._flush_event = None
|
|
132
|
+
self._flush_requested = False
|
|
133
|
+
|
|
134
|
+
if record is not None:
|
|
135
|
+
self._export(record)
|
|
136
|
+
continue
|
|
137
|
+
|
|
138
|
+
self._flush()
|
|
139
|
+
if flush_event is not None:
|
|
140
|
+
flush_event.set()
|
|
141
|
+
with self._condition:
|
|
142
|
+
if not self._pending and not self._flush_requested:
|
|
143
|
+
self._worker = None
|
|
144
|
+
return
|
|
145
|
+
|
|
146
|
+
def _export(self, record: dict[str, Any]) -> None:
|
|
147
|
+
for exporter in self._exporters:
|
|
148
|
+
try:
|
|
149
|
+
shaped = truncate_record(
|
|
150
|
+
record, exporter.max_record_size_bytes, exporter.render
|
|
151
|
+
)
|
|
152
|
+
exporter.export(shaped)
|
|
153
|
+
except Exception as exc: # noqa: BLE001 - one exporter must not break others
|
|
154
|
+
_logger.warning(
|
|
155
|
+
"durable-execution-telemetry: exporter %s failed: %s",
|
|
156
|
+
type(exporter).__name__,
|
|
157
|
+
exc,
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
def _flush(self) -> None:
|
|
161
|
+
for exporter in self._exporters:
|
|
162
|
+
try:
|
|
163
|
+
exporter.flush()
|
|
164
|
+
except Exception as exc: # noqa: BLE001 - one exporter must not break others
|
|
165
|
+
_logger.warning(
|
|
166
|
+
"durable-execution-telemetry: exporter %s flush failed: %s",
|
|
167
|
+
type(exporter).__name__,
|
|
168
|
+
exc,
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
# Test helpers.
|
|
172
|
+
def _worker_alive(self) -> bool:
|
|
173
|
+
with self._condition:
|
|
174
|
+
return self._worker is not None and self._worker.is_alive()
|
|
175
|
+
|
|
176
|
+
def _pending_count(self) -> int:
|
|
177
|
+
with self._condition:
|
|
178
|
+
return len(self._pending)
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026-present Amazon.com, Inc. or its affiliates.
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
"""First-party Durable Execution Telemetry exporters.
|
|
5
|
+
|
|
6
|
+
One module per destination, so no single file accretes every backend's imports
|
|
7
|
+
and optional dependencies. Concrete exporters are re-exported here so the
|
|
8
|
+
public import path is stable:
|
|
9
|
+
``from aws_durable_execution_sdk_python_telemetry_exporter.exporters import S3Exporter``.
|
|
10
|
+
Shared serialization and transport helpers live in the private ``_common``
|
|
11
|
+
module.
|
|
12
|
+
|
|
13
|
+
Every exporter serializes the curated record as compact JSON (no whitespace,
|
|
14
|
+
non-ASCII preserved). Records are written verbatim -- no synthetic emission.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
from aws_durable_execution_sdk_python_telemetry_exporter.exporters.aurora_exporter import (
|
|
20
|
+
AuroraEngine,
|
|
21
|
+
AuroraExporter,
|
|
22
|
+
)
|
|
23
|
+
from aws_durable_execution_sdk_python_telemetry_exporter.exporters.cloudwatch_logs_exporter import (
|
|
24
|
+
CloudWatchLogsExporter,
|
|
25
|
+
)
|
|
26
|
+
from aws_durable_execution_sdk_python_telemetry_exporter.exporters.dynamodb_exporter import (
|
|
27
|
+
DynamoDBExporter,
|
|
28
|
+
)
|
|
29
|
+
from aws_durable_execution_sdk_python_telemetry_exporter.exporters.eventbridge_exporter import (
|
|
30
|
+
EventBridgeExporter,
|
|
31
|
+
)
|
|
32
|
+
from aws_durable_execution_sdk_python_telemetry_exporter.exporters.file_exporter import (
|
|
33
|
+
FileExporter,
|
|
34
|
+
FileMode,
|
|
35
|
+
)
|
|
36
|
+
from aws_durable_execution_sdk_python_telemetry_exporter.exporters.firehose_exporter import (
|
|
37
|
+
FirehoseExporter,
|
|
38
|
+
)
|
|
39
|
+
from aws_durable_execution_sdk_python_telemetry_exporter.exporters.http_exporter import (
|
|
40
|
+
HttpExporter,
|
|
41
|
+
HttpMethod,
|
|
42
|
+
)
|
|
43
|
+
from aws_durable_execution_sdk_python_telemetry_exporter.exporters.lambda_log_exporter import (
|
|
44
|
+
LambdaLogExporter,
|
|
45
|
+
)
|
|
46
|
+
from aws_durable_execution_sdk_python_telemetry_exporter.exporters.opensearch_exporter import (
|
|
47
|
+
OpenSearchAuth,
|
|
48
|
+
OpenSearchExporter,
|
|
49
|
+
)
|
|
50
|
+
from aws_durable_execution_sdk_python_telemetry_exporter.exporters.otel_exporter import (
|
|
51
|
+
OTelExporter,
|
|
52
|
+
OTelProtocol,
|
|
53
|
+
)
|
|
54
|
+
from aws_durable_execution_sdk_python_telemetry_exporter.exporters.redshift_exporter import (
|
|
55
|
+
RedshiftExporter,
|
|
56
|
+
)
|
|
57
|
+
from aws_durable_execution_sdk_python_telemetry_exporter.exporters.s3_exporter import (
|
|
58
|
+
S3Exporter,
|
|
59
|
+
S3Partitioning,
|
|
60
|
+
)
|
|
61
|
+
from aws_durable_execution_sdk_python_telemetry_exporter.exporters.sqs_exporter import (
|
|
62
|
+
SQSExporter,
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
__all__ = [
|
|
67
|
+
"AuroraEngine",
|
|
68
|
+
"AuroraExporter",
|
|
69
|
+
"CloudWatchLogsExporter",
|
|
70
|
+
"DynamoDBExporter",
|
|
71
|
+
"EventBridgeExporter",
|
|
72
|
+
"FileExporter",
|
|
73
|
+
"FileMode",
|
|
74
|
+
"FirehoseExporter",
|
|
75
|
+
"HttpExporter",
|
|
76
|
+
"HttpMethod",
|
|
77
|
+
"LambdaLogExporter",
|
|
78
|
+
"OTelExporter",
|
|
79
|
+
"OTelProtocol",
|
|
80
|
+
"OpenSearchAuth",
|
|
81
|
+
"OpenSearchExporter",
|
|
82
|
+
"RedshiftExporter",
|
|
83
|
+
"S3Exporter",
|
|
84
|
+
"S3Partitioning",
|
|
85
|
+
"SQSExporter",
|
|
86
|
+
]
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026-present Amazon.com, Inc. or its affiliates.
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
"""Shared serialization helpers for the Durable Execution Telemetry exporters.
|
|
5
|
+
|
|
6
|
+
Kept private to the ``exporters`` package: every backend needs the same
|
|
7
|
+
JS-compatible compact JSON encoding and the same key/file-name sanitizer, so
|
|
8
|
+
they live here rather than being duplicated per exporter module.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import datetime
|
|
14
|
+
import json
|
|
15
|
+
import re
|
|
16
|
+
import urllib.error
|
|
17
|
+
import urllib.request
|
|
18
|
+
from typing import Any
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
_SQL_IDENTIFIER = re.compile(r"^[a-zA-Z_][a-zA-Z0-9_]*$")
|
|
22
|
+
# Upper bound on how much of a non-2xx response body is read for diagnostics.
|
|
23
|
+
_MAX_ERROR_BODY_BYTES = 64 * 1024
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class _NoRedirect(urllib.request.HTTPRedirectHandler):
|
|
27
|
+
"""Refuse every redirect so a 3xx surfaces as a failed status.
|
|
28
|
+
|
|
29
|
+
Following a redirect would re-send a POST as a body-less GET and forward
|
|
30
|
+
configured credential headers to the new location.
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
def redirect_request( # type: ignore[override] # stdlib signature has no hints
|
|
34
|
+
self, req: Any, fp: Any, code: int, msg: str, headers: Any, newurl: str
|
|
35
|
+
) -> None:
|
|
36
|
+
return None
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
_OPENER = urllib.request.build_opener(_NoRedirect())
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def compact_dumps(value: Any) -> str:
|
|
43
|
+
"""Serialize ``value`` as compact JSON (no whitespace, non-ASCII preserved).
|
|
44
|
+
|
|
45
|
+
Matches the JS exporters' ``JSON.stringify`` output so the wire bytes are
|
|
46
|
+
identical across SDKs.
|
|
47
|
+
"""
|
|
48
|
+
return json.dumps(value, separators=(",", ":"), ensure_ascii=False)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def sanitize(value: str) -> str:
|
|
52
|
+
"""Replace characters unsafe for object keys / file names with ``_``."""
|
|
53
|
+
return re.sub(r"[^a-zA-Z0-9._-]", "_", value)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def sql_identifier(name: str) -> str:
|
|
57
|
+
"""Return ``name`` if it is a plain SQL identifier, else raise ``ValueError``.
|
|
58
|
+
|
|
59
|
+
Table and schema names are interpolated into SQL text, so only letters,
|
|
60
|
+
digits, and underscores are accepted.
|
|
61
|
+
"""
|
|
62
|
+
if not _SQL_IDENTIFIER.match(name):
|
|
63
|
+
msg = (
|
|
64
|
+
f'Invalid SQL identifier: "{name}". '
|
|
65
|
+
"Only letters, digits, and underscores are allowed."
|
|
66
|
+
)
|
|
67
|
+
raise ValueError(msg)
|
|
68
|
+
return name
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def parse_iso_datetime(value: str) -> datetime.datetime:
|
|
72
|
+
"""Parse an ISO-8601 timestamp (``Z`` or offset) into an aware UTC datetime."""
|
|
73
|
+
parsed = datetime.datetime.fromisoformat(value.replace("Z", "+00:00"))
|
|
74
|
+
if parsed.tzinfo is None:
|
|
75
|
+
parsed = parsed.replace(tzinfo=datetime.UTC)
|
|
76
|
+
return parsed.astimezone(datetime.UTC)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def http_send(
|
|
80
|
+
method: str,
|
|
81
|
+
url: str,
|
|
82
|
+
headers: dict[str, str],
|
|
83
|
+
body: bytes,
|
|
84
|
+
timeout: float | None = None,
|
|
85
|
+
) -> tuple[int, str, str]:
|
|
86
|
+
"""Send one HTTP request and return ``(status, reason, error_text)``.
|
|
87
|
+
|
|
88
|
+
A non-2xx status is returned, not raised, so callers build their own error
|
|
89
|
+
message. Redirects are not followed: a 3xx is returned like any other
|
|
90
|
+
failure. ``error_text`` is the first ``_MAX_ERROR_BODY_BYTES`` of a non-2xx
|
|
91
|
+
response body and empty on success; a success body is never read. Network
|
|
92
|
+
errors and timeouts propagate. ``timeout`` is ``urllib``'s per-socket-
|
|
93
|
+
operation timeout: it bounds the connect, each write of the request, and
|
|
94
|
+
each read of the status line, headers, and any error body separately, not
|
|
95
|
+
the request as a whole. A peer that keeps consuming or sending bytes
|
|
96
|
+
slowly can outlive it.
|
|
97
|
+
"""
|
|
98
|
+
request = urllib.request.Request(url, data=body, method=method)
|
|
99
|
+
for key, value in headers.items():
|
|
100
|
+
request.add_header(key, value)
|
|
101
|
+
try:
|
|
102
|
+
with _OPENER.open(request, timeout=timeout) as response: # noqa: S310
|
|
103
|
+
return int(response.status), str(response.reason or ""), ""
|
|
104
|
+
except urllib.error.HTTPError as exc:
|
|
105
|
+
try:
|
|
106
|
+
detail = exc.read(_MAX_ERROR_BODY_BYTES).decode("utf-8", errors="replace")
|
|
107
|
+
except Exception: # noqa: BLE001 - the body is best-effort detail only
|
|
108
|
+
detail = ""
|
|
109
|
+
return int(exc.code), str(exc.reason or ""), detail
|