otlp-test-data 0.9.0__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
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: otlp-test-data
|
|
3
|
+
Version: 0.9.0
|
|
4
|
+
Summary: Produces OTLP data using OTEL instrumentation
|
|
5
|
+
Classifier: Development Status :: 3 - Alpha
|
|
6
|
+
Classifier: Intended Audience :: Developers
|
|
7
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
8
|
+
Classifier: Natural Language :: English
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Classifier: Programming Language :: Python
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
19
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
20
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
21
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
22
|
+
Classifier: Topic :: Software Development :: Testing
|
|
23
|
+
Classifier: Topic :: Software Development :: Testing :: Traffic Generation
|
|
24
|
+
Classifier: Framework :: OpenTelemetry
|
|
25
|
+
Classifier: Framework :: OpenTelemetry :: Exporters
|
|
26
|
+
Requires-Python: >=3.8
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
Requires-Dist: freezegun~=1.5
|
|
29
|
+
Requires-Dist: opentelemetry-api~=1.30
|
|
30
|
+
Requires-Dist: opentelemetry-exporter-otlp~=1.30
|
|
31
|
+
Requires-Dist: opentelemetry-exporter-otlp-proto-http~=1.30
|
|
32
|
+
|
|
33
|
+
# otlp-test-data
|
|
34
|
+
|
|
35
|
+
Produces OTLP data using OTEL instrumentation.
|
|
36
|
+
|
|
37
|
+
### Features
|
|
38
|
+
|
|
39
|
+
- fixed, configurable timestamps
|
|
40
|
+
- aims to cover as much of OTEL API as possible
|
|
41
|
+
- aims to cover all valid data types
|
|
42
|
+
|
|
43
|
+
### Limitations
|
|
44
|
+
|
|
45
|
+
- currently only tracing data is generated, PRs are welcome to add metrics and logs data
|
|
46
|
+
- data is generated in process, remote (forwarded) spans are not supported
|
|
47
|
+
|
|
48
|
+
### TODO
|
|
49
|
+
|
|
50
|
+
- Events
|
|
51
|
+
- Links
|
|
52
|
+
- Baggage
|
|
53
|
+
- Schemata, when https://github.com/open-telemetry/opentelemetry-python/pull/4359 lands
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
otlp_test_data.py,sha256=nawhyR0ClypJ_1L1denG9uTcydqqAfqmuPU5xqwc_IM,2867
|
|
2
|
+
otlp_test_data-0.9.0.dist-info/METADATA,sha256=aGGgCwBapIaHfnZHHq8B1gh8EQN_8bPdPRQRx6QryIk,1949
|
|
3
|
+
otlp_test_data-0.9.0.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
4
|
+
otlp_test_data-0.9.0.dist-info/top_level.txt,sha256=ft5rEmyMAUMgA-09EOjh--RP05FB8jlthlJ1FywFTso,15
|
|
5
|
+
otlp_test_data-0.9.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
otlp_test_data
|
otlp_test_data.py
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import base64
|
|
4
|
+
import dataclasses
|
|
5
|
+
import json
|
|
6
|
+
import random
|
|
7
|
+
from typing import Sequence, TYPE_CHECKING
|
|
8
|
+
from typing_extensions import reveal_type as reveal_type # temp
|
|
9
|
+
|
|
10
|
+
import freezegun
|
|
11
|
+
from google.protobuf.json_format import MessageToDict
|
|
12
|
+
from opentelemetry.exporter.otlp.proto.common._internal import trace_encoder
|
|
13
|
+
from opentelemetry.sdk.trace import TracerProvider
|
|
14
|
+
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
|
|
15
|
+
from opentelemetry.sdk.trace.export.in_memory_span_exporter import InMemorySpanExporter
|
|
16
|
+
|
|
17
|
+
if TYPE_CHECKING:
|
|
18
|
+
from google.protobuf.message import Message
|
|
19
|
+
from opentelemetry.sdk.trace import ReadableSpan
|
|
20
|
+
from opentelemetry.proto.collector.trace.v1.trace_service_pb2 import (
|
|
21
|
+
ExportTraceServiceRequest,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@dataclasses.dataclass
|
|
26
|
+
class Config:
|
|
27
|
+
start_time: str = "2020-01-01 00:00:00Z"
|
|
28
|
+
random_seed: int = 42
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
time = None
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def sample_proto(config: Config) -> bytes:
|
|
35
|
+
return _proto_to_bytes(_spans_to_proto_object(sample_spans(config)))
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def sample_json(config: Config) -> bytes:
|
|
39
|
+
return _proto_to_json(_spans_to_proto_object(sample_spans(config)))
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def sample_spans(config: Config) -> Sequence[ReadableSpan]:
|
|
43
|
+
"""Creates and finishes two spans, then returns them as a list."""
|
|
44
|
+
global time
|
|
45
|
+
tracer_provider = TracerProvider()
|
|
46
|
+
exporter = InMemorySpanExporter()
|
|
47
|
+
tracer_provider.add_span_processor(SimpleSpanProcessor(exporter))
|
|
48
|
+
tracer = tracer_provider.get_tracer(__name__)
|
|
49
|
+
|
|
50
|
+
with freezegun.freeze_time(config.start_time) as time:
|
|
51
|
+
random.seed(config.random_seed)
|
|
52
|
+
|
|
53
|
+
# FIXME the workload section is expected to grow a lot
|
|
54
|
+
with tracer.start_as_current_span("span-one"):
|
|
55
|
+
time.tick()
|
|
56
|
+
with tracer.start_as_current_span("span-two"):
|
|
57
|
+
time.tick()
|
|
58
|
+
|
|
59
|
+
return exporter.get_finished_spans()
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def _spans_to_proto_object(spans: Sequence[ReadableSpan]) -> ExportTraceServiceRequest:
|
|
63
|
+
return trace_encoder.encode_spans(spans)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _proto_to_bytes(data: Message) -> bytes:
|
|
67
|
+
return data.SerializePartialToString()
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
# FIXME: there are probably 3 different enumerated types in the API
|
|
71
|
+
def _proto_to_json(data: Message) -> bytes:
|
|
72
|
+
dic = MessageToDict(data)
|
|
73
|
+
|
|
74
|
+
for rs in dic["resourceSpans"]:
|
|
75
|
+
for ss in rs["scopeSpans"]:
|
|
76
|
+
for sp in ss["spans"]:
|
|
77
|
+
for k in "parentSpanId spanId traceId".split():
|
|
78
|
+
if k in sp:
|
|
79
|
+
sp[k] = base64.b64decode(sp[k]).hex()
|
|
80
|
+
sp["kind"] = {
|
|
81
|
+
"SPAN_KIND_UNSPECIFIED": 0,
|
|
82
|
+
"SPAN_KIND_INTERNAL": 1,
|
|
83
|
+
"SPAN_KIND_SERVER": 2,
|
|
84
|
+
"SPAN_KIND_CLIENT": 3,
|
|
85
|
+
"SPAN_KIND_PRODUCER": 4,
|
|
86
|
+
"SPAN_KIND_CONSUMER": 5,
|
|
87
|
+
}[sp["kind"]]
|
|
88
|
+
|
|
89
|
+
return json.dumps(dic).encode("utf-8")
|