partial-span-processor 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.
- partial_span_processor/__init__.py +473 -0
- partial_span_processor-0.0.1.dist-info/LICENSE +201 -0
- partial_span_processor-0.0.1.dist-info/METADATA +23 -0
- partial_span_processor-0.0.1.dist-info/RECORD +6 -0
- partial_span_processor-0.0.1.dist-info/WHEEL +5 -0
- partial_span_processor-0.0.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,473 @@
|
|
|
1
|
+
import collections
|
|
2
|
+
import logging
|
|
3
|
+
import os
|
|
4
|
+
import queue
|
|
5
|
+
import threading
|
|
6
|
+
import time
|
|
7
|
+
import typing
|
|
8
|
+
from os import environ
|
|
9
|
+
from time import time_ns
|
|
10
|
+
|
|
11
|
+
from opentelemetry._logs.severity import SeverityNumber
|
|
12
|
+
from opentelemetry.context import (
|
|
13
|
+
_SUPPRESS_INSTRUMENTATION_KEY,
|
|
14
|
+
Context,
|
|
15
|
+
attach,
|
|
16
|
+
detach,
|
|
17
|
+
set_value,
|
|
18
|
+
)
|
|
19
|
+
from opentelemetry.exporter.otlp.proto.common.trace_encoder import encode_spans
|
|
20
|
+
from opentelemetry.proto.trace.v1 import trace_pb2
|
|
21
|
+
from opentelemetry.sdk._logs import LogData, LogRecord, LogRecordProcessor
|
|
22
|
+
from opentelemetry.sdk.environment_variables import (
|
|
23
|
+
OTEL_BSP_EXPORT_TIMEOUT,
|
|
24
|
+
OTEL_BSP_MAX_EXPORT_BATCH_SIZE,
|
|
25
|
+
OTEL_BSP_MAX_QUEUE_SIZE,
|
|
26
|
+
OTEL_BSP_SCHEDULE_DELAY,
|
|
27
|
+
)
|
|
28
|
+
from opentelemetry.sdk.trace import (
|
|
29
|
+
ReadableSpan,
|
|
30
|
+
Span,
|
|
31
|
+
SpanProcessor,
|
|
32
|
+
)
|
|
33
|
+
from opentelemetry.sdk.trace.export import SpanExporter, _BSP_RESET_ONCE
|
|
34
|
+
from opentelemetry.sdk.trace.export import _FlushRequest
|
|
35
|
+
from opentelemetry.trace import TraceFlags
|
|
36
|
+
|
|
37
|
+
_DEFAULT_SCHEDULE_DELAY_MILLIS = 5000
|
|
38
|
+
_DEFAULT_MAX_EXPORT_BATCH_SIZE = 512
|
|
39
|
+
_DEFAULT_EXPORT_TIMEOUT_MILLIS = 30000
|
|
40
|
+
_DEFAULT_MAX_QUEUE_SIZE = 2048
|
|
41
|
+
_ENV_VAR_INT_VALUE_ERROR_MESSAGE = (
|
|
42
|
+
"Unable to parse value for %s as integer. Defaulting to %s."
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
logger = logging.getLogger(__name__)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class PartialSpanProcessor(SpanProcessor):
|
|
49
|
+
"""Partial span processor implementation.
|
|
50
|
+
|
|
51
|
+
`PartialSpanProcessor` is an implementation of `SpanProcessor` that
|
|
52
|
+
batches ended spans and pushes them to the configured `SpanExporter`.
|
|
53
|
+
|
|
54
|
+
`PartialSpanProcessor` is configurable with the following environment
|
|
55
|
+
variables which correspond to constructor parameters:
|
|
56
|
+
|
|
57
|
+
- :envvar:`OTEL_BSP_SCHEDULE_DELAY`
|
|
58
|
+
- :envvar:`OTEL_BSP_MAX_QUEUE_SIZE`
|
|
59
|
+
- :envvar:`OTEL_BSP_MAX_EXPORT_BATCH_SIZE`
|
|
60
|
+
- :envvar:`OTEL_BSP_EXPORT_TIMEOUT`
|
|
61
|
+
"""
|
|
62
|
+
|
|
63
|
+
def __init__(
|
|
64
|
+
self,
|
|
65
|
+
span_exporter: SpanExporter,
|
|
66
|
+
log_processor: LogRecordProcessor,
|
|
67
|
+
max_queue_size: int = None,
|
|
68
|
+
schedule_delay_millis: float = None,
|
|
69
|
+
max_export_batch_size: int = None,
|
|
70
|
+
export_timeout_millis: float = None,
|
|
71
|
+
):
|
|
72
|
+
self.log_processor = log_processor
|
|
73
|
+
self.lock = threading.Lock()
|
|
74
|
+
|
|
75
|
+
if max_queue_size is None:
|
|
76
|
+
max_queue_size = PartialSpanProcessor._default_max_queue_size()
|
|
77
|
+
|
|
78
|
+
if schedule_delay_millis is None:
|
|
79
|
+
schedule_delay_millis = (
|
|
80
|
+
PartialSpanProcessor._default_schedule_delay_millis()
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
if max_export_batch_size is None:
|
|
84
|
+
max_export_batch_size = (
|
|
85
|
+
PartialSpanProcessor._default_max_export_batch_size()
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
if export_timeout_millis is None:
|
|
89
|
+
export_timeout_millis = (
|
|
90
|
+
PartialSpanProcessor._default_export_timeout_millis()
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
PartialSpanProcessor._validate_arguments(
|
|
94
|
+
max_queue_size, schedule_delay_millis, max_export_batch_size
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
self.span_exporter = span_exporter
|
|
98
|
+
self.queue = collections.deque([],
|
|
99
|
+
max_queue_size) # type: typing.Deque[Span]
|
|
100
|
+
self.worker_thread = threading.Thread(
|
|
101
|
+
name="OtelPartialSpanProcessor", target=self.worker, daemon=True
|
|
102
|
+
)
|
|
103
|
+
self.condition = threading.Condition(threading.Lock())
|
|
104
|
+
self._flush_request = None # type: typing.Optional[_FlushRequest]
|
|
105
|
+
self.schedule_delay_millis = schedule_delay_millis
|
|
106
|
+
self.max_export_batch_size = max_export_batch_size
|
|
107
|
+
self.max_queue_size = max_queue_size
|
|
108
|
+
self.export_timeout_millis = export_timeout_millis
|
|
109
|
+
self.done = False
|
|
110
|
+
# flag that indicates that spans are being dropped
|
|
111
|
+
self._spans_dropped = False
|
|
112
|
+
# precallocated list to send spans to exporter
|
|
113
|
+
self.spans_list = [
|
|
114
|
+
None] * self.max_export_batch_size # type: typing.List[typing.Optional[Span]]
|
|
115
|
+
self.worker_thread.start()
|
|
116
|
+
if hasattr(os, "register_at_fork"):
|
|
117
|
+
os.register_at_fork(
|
|
118
|
+
after_in_child=self._at_fork_reinit) # pylint: disable=protected-access
|
|
119
|
+
self._pid = os.getpid()
|
|
120
|
+
self.active_spans = {}
|
|
121
|
+
self.ended_spans = queue.Queue()
|
|
122
|
+
|
|
123
|
+
def on_start(
|
|
124
|
+
self, span: Span, parent_context: typing.Optional[Context] = None
|
|
125
|
+
) -> None:
|
|
126
|
+
span_key = (span.context.trace_id, span.context.span_id)
|
|
127
|
+
with self.lock:
|
|
128
|
+
self.active_spans[span_key] = span
|
|
129
|
+
attributes = self.get_heartbeat_attributes()
|
|
130
|
+
|
|
131
|
+
log_data = get_logdata(span, attributes)
|
|
132
|
+
self.log_processor.emit(log_data)
|
|
133
|
+
|
|
134
|
+
def on_end(self, span: ReadableSpan) -> None:
|
|
135
|
+
span_key = (span.context.trace_id, span.context.span_id)
|
|
136
|
+
self.ended_spans.put((span_key, span))
|
|
137
|
+
|
|
138
|
+
attributes = {
|
|
139
|
+
"partial.event": "stop",
|
|
140
|
+
# TODO should this be removed?
|
|
141
|
+
"telemetry.logs.cluster": "partial",
|
|
142
|
+
"telemetry.logs.project": "span",
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
log_data = get_logdata(span, attributes)
|
|
146
|
+
self.log_processor.emit(log_data)
|
|
147
|
+
|
|
148
|
+
if self.done:
|
|
149
|
+
logger.warning("Already shutdown, dropping span.")
|
|
150
|
+
return
|
|
151
|
+
if not span.context.trace_flags.sampled:
|
|
152
|
+
return
|
|
153
|
+
if self._pid != os.getpid():
|
|
154
|
+
_BSP_RESET_ONCE.do_once(self._at_fork_reinit)
|
|
155
|
+
|
|
156
|
+
if len(self.queue) == self.max_queue_size:
|
|
157
|
+
if not self._spans_dropped:
|
|
158
|
+
logger.warning("Queue is full, likely spans will be dropped.")
|
|
159
|
+
self._spans_dropped = True
|
|
160
|
+
|
|
161
|
+
self.queue.appendleft(span)
|
|
162
|
+
|
|
163
|
+
if len(self.queue) >= self.max_export_batch_size:
|
|
164
|
+
with self.condition:
|
|
165
|
+
self.condition.notify()
|
|
166
|
+
|
|
167
|
+
def _at_fork_reinit(self):
|
|
168
|
+
self.condition = threading.Condition(threading.Lock())
|
|
169
|
+
self.queue.clear()
|
|
170
|
+
|
|
171
|
+
# worker_thread is local to a process, only the thread that issued fork continues
|
|
172
|
+
# to exist. A new worker thread must be started in child process.
|
|
173
|
+
self.worker_thread = threading.Thread(
|
|
174
|
+
name="OtelPartialSpanProcessor", target=self.worker, daemon=True
|
|
175
|
+
)
|
|
176
|
+
self.worker_thread.start()
|
|
177
|
+
self._pid = os.getpid()
|
|
178
|
+
|
|
179
|
+
def heartbeat(self):
|
|
180
|
+
# remove ended spans from active spans
|
|
181
|
+
with self.lock:
|
|
182
|
+
while not self.ended_spans.empty():
|
|
183
|
+
span_key, span = self.ended_spans.get()
|
|
184
|
+
self.active_spans.pop(span_key, None)
|
|
185
|
+
|
|
186
|
+
attributes = self.get_heartbeat_attributes()
|
|
187
|
+
|
|
188
|
+
with self.lock:
|
|
189
|
+
for span_key, span in self.active_spans.items():
|
|
190
|
+
log_data = get_logdata(span, attributes)
|
|
191
|
+
self.log_processor.emit(log_data)
|
|
192
|
+
|
|
193
|
+
def get_heartbeat_attributes(self):
|
|
194
|
+
return {
|
|
195
|
+
"partial.event": "heartbeat",
|
|
196
|
+
"partial.frequency": str(self._default_schedule_delay_millis())
|
|
197
|
+
+ "ms",
|
|
198
|
+
# TODO should this be removed?
|
|
199
|
+
"telemetry.logs.cluster": "partial",
|
|
200
|
+
"telemetry.logs.project": "span",
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
def worker(self):
|
|
204
|
+
timeout = self.schedule_delay_millis / 1e3
|
|
205
|
+
flush_request = None # type: typing.Optional[_FlushRequest]
|
|
206
|
+
while not self.done:
|
|
207
|
+
with self.condition:
|
|
208
|
+
if self.done:
|
|
209
|
+
# done flag may have changed, avoid waiting
|
|
210
|
+
break
|
|
211
|
+
flush_request = self._get_and_unset_flush_request()
|
|
212
|
+
if (
|
|
213
|
+
len(self.queue) < self.max_export_batch_size
|
|
214
|
+
and flush_request is None
|
|
215
|
+
):
|
|
216
|
+
self.condition.wait(timeout)
|
|
217
|
+
self.heartbeat()
|
|
218
|
+
flush_request = self._get_and_unset_flush_request()
|
|
219
|
+
if not self.queue:
|
|
220
|
+
# spurious notification, let's wait again, reset timeout
|
|
221
|
+
timeout = self.schedule_delay_millis / 1e3
|
|
222
|
+
self._notify_flush_request_finished(flush_request)
|
|
223
|
+
flush_request = None
|
|
224
|
+
continue
|
|
225
|
+
if self.done:
|
|
226
|
+
# missing spans will be sent when calling flush
|
|
227
|
+
break
|
|
228
|
+
|
|
229
|
+
# subtract the duration of this export call to the next timeout
|
|
230
|
+
start = time_ns()
|
|
231
|
+
self._export(flush_request)
|
|
232
|
+
end = time_ns()
|
|
233
|
+
duration = (end - start) / 1e9
|
|
234
|
+
timeout = self.schedule_delay_millis / 1e3 - duration
|
|
235
|
+
|
|
236
|
+
self._notify_flush_request_finished(flush_request)
|
|
237
|
+
flush_request = None
|
|
238
|
+
|
|
239
|
+
# there might have been a new flush request while export was running
|
|
240
|
+
# and before the done flag switched to true
|
|
241
|
+
with self.condition:
|
|
242
|
+
shutdown_flush_request = self._get_and_unset_flush_request()
|
|
243
|
+
|
|
244
|
+
# be sure that all spans are sent
|
|
245
|
+
self._drain_queue()
|
|
246
|
+
self._notify_flush_request_finished(flush_request)
|
|
247
|
+
self._notify_flush_request_finished(shutdown_flush_request)
|
|
248
|
+
|
|
249
|
+
def _get_and_unset_flush_request(
|
|
250
|
+
self,
|
|
251
|
+
) -> typing.Optional[_FlushRequest]:
|
|
252
|
+
"""Returns the current flush request and makes it invisible to the
|
|
253
|
+
worker thread for subsequent calls.
|
|
254
|
+
"""
|
|
255
|
+
flush_request = self._flush_request
|
|
256
|
+
self._flush_request = None
|
|
257
|
+
if flush_request is not None:
|
|
258
|
+
flush_request.num_spans = len(self.queue)
|
|
259
|
+
return flush_request
|
|
260
|
+
|
|
261
|
+
@staticmethod
|
|
262
|
+
def _notify_flush_request_finished(
|
|
263
|
+
flush_request: typing.Optional[_FlushRequest],
|
|
264
|
+
):
|
|
265
|
+
"""Notifies the flush initiator(s) waiting on the given request/event
|
|
266
|
+
that the flush operation was finished.
|
|
267
|
+
"""
|
|
268
|
+
if flush_request is not None:
|
|
269
|
+
flush_request.event.set()
|
|
270
|
+
|
|
271
|
+
def _get_or_create_flush_request(self) -> _FlushRequest:
|
|
272
|
+
"""Either returns the current active flush event or creates a new one.
|
|
273
|
+
|
|
274
|
+
The flush event will be visible and read by the worker thread before an
|
|
275
|
+
export operation starts. Callers of a flush operation may wait on the
|
|
276
|
+
returned event to be notified when the flush/export operation was
|
|
277
|
+
finished.
|
|
278
|
+
|
|
279
|
+
This method is not thread-safe, i.e. callers need to take care about
|
|
280
|
+
synchronization/locking.
|
|
281
|
+
"""
|
|
282
|
+
if self._flush_request is None:
|
|
283
|
+
self._flush_request = _FlushRequest()
|
|
284
|
+
return self._flush_request
|
|
285
|
+
|
|
286
|
+
def _export(self, flush_request: typing.Optional[_FlushRequest]):
|
|
287
|
+
"""Exports spans considering the given flush_request.
|
|
288
|
+
|
|
289
|
+
In case of a given flush_requests spans are exported in batches until
|
|
290
|
+
the number of exported spans reached or exceeded the number of spans in
|
|
291
|
+
the flush request.
|
|
292
|
+
In no flush_request was given at most max_export_batch_size spans are
|
|
293
|
+
exported.
|
|
294
|
+
"""
|
|
295
|
+
if not flush_request:
|
|
296
|
+
self._export_batch()
|
|
297
|
+
return
|
|
298
|
+
|
|
299
|
+
num_spans = flush_request.num_spans
|
|
300
|
+
while self.queue:
|
|
301
|
+
num_exported = self._export_batch()
|
|
302
|
+
num_spans -= num_exported
|
|
303
|
+
|
|
304
|
+
if num_spans <= 0:
|
|
305
|
+
break
|
|
306
|
+
|
|
307
|
+
def _export_batch(self) -> int:
|
|
308
|
+
"""Exports at most max_export_batch_size spans and returns the number of
|
|
309
|
+
exported spans.
|
|
310
|
+
"""
|
|
311
|
+
idx = 0
|
|
312
|
+
# currently only a single thread acts as consumer, so queue.pop() will
|
|
313
|
+
# not raise an exception
|
|
314
|
+
while idx < self.max_export_batch_size and self.queue:
|
|
315
|
+
self.spans_list[idx] = self.queue.pop()
|
|
316
|
+
idx += 1
|
|
317
|
+
token = attach(set_value(_SUPPRESS_INSTRUMENTATION_KEY, True))
|
|
318
|
+
try:
|
|
319
|
+
# Ignore type b/c the Optional[None]+slicing is too "clever"
|
|
320
|
+
# for mypy
|
|
321
|
+
self.span_exporter.export(self.spans_list[:idx]) # type: ignore
|
|
322
|
+
except Exception: # pylint: disable=broad-exception-caught
|
|
323
|
+
logger.exception("Exception while exporting Span batch.")
|
|
324
|
+
detach(token)
|
|
325
|
+
|
|
326
|
+
# clean up list
|
|
327
|
+
for index in range(idx):
|
|
328
|
+
self.spans_list[index] = None
|
|
329
|
+
return idx
|
|
330
|
+
|
|
331
|
+
def _drain_queue(self):
|
|
332
|
+
"""Export all elements until queue is empty.
|
|
333
|
+
|
|
334
|
+
Can only be called from the worker thread context because it invokes
|
|
335
|
+
`export` that is not thread safe.
|
|
336
|
+
"""
|
|
337
|
+
while self.queue:
|
|
338
|
+
self._export_batch()
|
|
339
|
+
|
|
340
|
+
def force_flush(self, timeout_millis: int = None) -> bool:
|
|
341
|
+
if timeout_millis is None:
|
|
342
|
+
timeout_millis = self.export_timeout_millis
|
|
343
|
+
|
|
344
|
+
if self.done:
|
|
345
|
+
logger.warning("Already shutdown, ignoring call to force_flush().")
|
|
346
|
+
return True
|
|
347
|
+
|
|
348
|
+
with self.condition:
|
|
349
|
+
flush_request = self._get_or_create_flush_request()
|
|
350
|
+
# signal the worker thread to flush and wait for it to finish
|
|
351
|
+
self.condition.notify_all()
|
|
352
|
+
|
|
353
|
+
# wait for token to be processed
|
|
354
|
+
ret = flush_request.event.wait(timeout_millis / 1e3)
|
|
355
|
+
if not ret:
|
|
356
|
+
logger.warning("Timeout was exceeded in force_flush().")
|
|
357
|
+
return ret
|
|
358
|
+
|
|
359
|
+
def shutdown(self) -> None:
|
|
360
|
+
# signal the worker thread to finish and then wait for it
|
|
361
|
+
self.done = True
|
|
362
|
+
with self.condition:
|
|
363
|
+
self.condition.notify_all()
|
|
364
|
+
self.worker_thread.join()
|
|
365
|
+
self.span_exporter.shutdown()
|
|
366
|
+
|
|
367
|
+
@staticmethod
|
|
368
|
+
def _default_max_queue_size():
|
|
369
|
+
try:
|
|
370
|
+
return int(
|
|
371
|
+
environ.get(OTEL_BSP_MAX_QUEUE_SIZE, _DEFAULT_MAX_QUEUE_SIZE)
|
|
372
|
+
)
|
|
373
|
+
except ValueError:
|
|
374
|
+
logger.exception(
|
|
375
|
+
_ENV_VAR_INT_VALUE_ERROR_MESSAGE,
|
|
376
|
+
OTEL_BSP_MAX_QUEUE_SIZE,
|
|
377
|
+
_DEFAULT_MAX_QUEUE_SIZE,
|
|
378
|
+
)
|
|
379
|
+
return _DEFAULT_MAX_QUEUE_SIZE
|
|
380
|
+
|
|
381
|
+
@staticmethod
|
|
382
|
+
def _default_schedule_delay_millis():
|
|
383
|
+
try:
|
|
384
|
+
return int(
|
|
385
|
+
environ.get(
|
|
386
|
+
OTEL_BSP_SCHEDULE_DELAY, _DEFAULT_SCHEDULE_DELAY_MILLIS
|
|
387
|
+
)
|
|
388
|
+
)
|
|
389
|
+
except ValueError:
|
|
390
|
+
logger.exception(
|
|
391
|
+
_ENV_VAR_INT_VALUE_ERROR_MESSAGE,
|
|
392
|
+
OTEL_BSP_SCHEDULE_DELAY,
|
|
393
|
+
_DEFAULT_SCHEDULE_DELAY_MILLIS,
|
|
394
|
+
)
|
|
395
|
+
return _DEFAULT_SCHEDULE_DELAY_MILLIS
|
|
396
|
+
|
|
397
|
+
@staticmethod
|
|
398
|
+
def _default_max_export_batch_size():
|
|
399
|
+
try:
|
|
400
|
+
return int(
|
|
401
|
+
environ.get(
|
|
402
|
+
OTEL_BSP_MAX_EXPORT_BATCH_SIZE,
|
|
403
|
+
_DEFAULT_MAX_EXPORT_BATCH_SIZE,
|
|
404
|
+
)
|
|
405
|
+
)
|
|
406
|
+
except ValueError:
|
|
407
|
+
logger.exception(
|
|
408
|
+
_ENV_VAR_INT_VALUE_ERROR_MESSAGE,
|
|
409
|
+
OTEL_BSP_MAX_EXPORT_BATCH_SIZE,
|
|
410
|
+
_DEFAULT_MAX_EXPORT_BATCH_SIZE,
|
|
411
|
+
)
|
|
412
|
+
return _DEFAULT_MAX_EXPORT_BATCH_SIZE
|
|
413
|
+
|
|
414
|
+
@staticmethod
|
|
415
|
+
def _default_export_timeout_millis():
|
|
416
|
+
try:
|
|
417
|
+
return int(
|
|
418
|
+
environ.get(
|
|
419
|
+
OTEL_BSP_EXPORT_TIMEOUT, _DEFAULT_EXPORT_TIMEOUT_MILLIS
|
|
420
|
+
)
|
|
421
|
+
)
|
|
422
|
+
except ValueError:
|
|
423
|
+
logger.exception(
|
|
424
|
+
_ENV_VAR_INT_VALUE_ERROR_MESSAGE,
|
|
425
|
+
OTEL_BSP_EXPORT_TIMEOUT,
|
|
426
|
+
_DEFAULT_EXPORT_TIMEOUT_MILLIS,
|
|
427
|
+
)
|
|
428
|
+
return _DEFAULT_EXPORT_TIMEOUT_MILLIS
|
|
429
|
+
|
|
430
|
+
@staticmethod
|
|
431
|
+
def _validate_arguments(
|
|
432
|
+
max_queue_size, schedule_delay_millis, max_export_batch_size
|
|
433
|
+
):
|
|
434
|
+
if max_queue_size <= 0:
|
|
435
|
+
raise ValueError("max_queue_size must be a positive integer.")
|
|
436
|
+
|
|
437
|
+
if schedule_delay_millis <= 0:
|
|
438
|
+
raise ValueError("schedule_delay_millis must be positive.")
|
|
439
|
+
|
|
440
|
+
if max_export_batch_size <= 0:
|
|
441
|
+
raise ValueError(
|
|
442
|
+
"max_export_batch_size must be a positive integer."
|
|
443
|
+
)
|
|
444
|
+
|
|
445
|
+
if max_export_batch_size > max_queue_size:
|
|
446
|
+
raise ValueError(
|
|
447
|
+
"max_export_batch_size must be less than or equal to max_queue_size."
|
|
448
|
+
)
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
def get_logdata(span, attributes):
|
|
452
|
+
span_context = Span.get_span_context(span)
|
|
453
|
+
|
|
454
|
+
enc_spans = encode_spans([span]).resource_spans
|
|
455
|
+
traces_data = trace_pb2.TracesData()
|
|
456
|
+
traces_data.resource_spans.extend(enc_spans)
|
|
457
|
+
serialized_traces_data = traces_data.SerializeToString()
|
|
458
|
+
|
|
459
|
+
log_record = LogRecord(
|
|
460
|
+
timestamp=time.time_ns(),
|
|
461
|
+
observed_timestamp=time.time_ns(),
|
|
462
|
+
trace_id=span_context.trace_id,
|
|
463
|
+
span_id=span_context.span_id,
|
|
464
|
+
trace_flags=TraceFlags().get_default(),
|
|
465
|
+
severity_text="INFO",
|
|
466
|
+
severity_number=SeverityNumber.INFO,
|
|
467
|
+
body=bytes(serialized_traces_data),
|
|
468
|
+
attributes=attributes,
|
|
469
|
+
)
|
|
470
|
+
log_data = LogData(
|
|
471
|
+
log_record=log_record, instrumentation_scope=span.instrumentation_scope
|
|
472
|
+
)
|
|
473
|
+
return log_data
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: partial-span-processor
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: OTEL Python SDK extension supporting partial spans
|
|
5
|
+
Author-email: Mladjan Gadzic <gadzic.mladjan@gmail.com>
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/mladjan-gadzic/partial-span-processor
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.13
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Requires-Dist: opentelemetry-api
|
|
14
|
+
Requires-Dist: opentelemetry-exporter-otlp
|
|
15
|
+
Requires-Dist: opentelemetry-exporter-otlp-proto-common
|
|
16
|
+
Requires-Dist: opentelemetry-exporter-otlp-proto-grpc
|
|
17
|
+
Requires-Dist: opentelemetry-exporter-otlp-proto-http
|
|
18
|
+
Requires-Dist: opentelemetry-proto
|
|
19
|
+
Requires-Dist: opentelemetry-sdk
|
|
20
|
+
Requires-Dist: opentelemetry-semantic-conventions
|
|
21
|
+
|
|
22
|
+
# partial-span-processor
|
|
23
|
+
OTEL Python SDK extension supporting partial spans
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
partial_span_processor/__init__.py,sha256=hhBQGqKZTW1ewi_GOwsIZHlg0xCnDlrZ3_hz1Al7uw0,14976
|
|
2
|
+
partial_span_processor-0.0.1.dist-info/LICENSE,sha256=QwcOLU5TJoTeUhuIXzhdCEEDDvorGiC6-3YTOl4TecE,11356
|
|
3
|
+
partial_span_processor-0.0.1.dist-info/METADATA,sha256=fkMRJEhzwbbknM-4f-k-uz9H3lh1A16PbzXhQk5MaJI,898
|
|
4
|
+
partial_span_processor-0.0.1.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
5
|
+
partial_span_processor-0.0.1.dist-info/top_level.txt,sha256=Gr4J4c99bRajjGFMUL4e2MqsaW0WI56AEdzJ3aUTlo8,23
|
|
6
|
+
partial_span_processor-0.0.1.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
partial_span_processor
|