-
Notifications
You must be signed in to change notification settings - Fork 0
/
otlp_test.py
60 lines (53 loc) · 1.99 KB
/
otlp_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from grpc import insecure_channel
from opentelemetry import trace
from opentelemetry.exporter.otlp import Protocol, Compression, \
OTLPExporter, OTLPSpanExporter
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import (
BatchExportSpanProcessor,
SimpleExportSpanProcessor
)
from opentelemetry.exporter import otlp
if __name__ == '__main__':
OTLPExporter(ExporterType.SPAN)
exit(0)
# file = _load_credential_from_file("/root/service.pem")
# a = 1
# exit(0)
# channel = insecure_channel("host.docker.internal:55680")
trace.set_tracer_provider(TracerProvider())
trace.get_tracer_provider().add_span_processor(
BatchExportSpanProcessor(
OTLPSpanExporter(
"host.docker.internal:55680",
# insecure=True,
# compression=Compression.NONE,
# headers="rob=testing",
cert_file="/root/service.pem"
)
)
#
# BatchExportSpanProcessor(
# OTLPSpanExporter(
# protocol=Protocol.HTTP_PROTOBUF,
# endpoint="https://host.docker.internal:55681/v1/traces",
# insecure=False,
# cert_file="/root/ca.crt",
# compression=Compression.DEFLATE,
# )
# )
)
provider = trace.get_tracer_provider()
tracer = trace.get_tracer(__name__, "1.1r")
with tracer.start_as_current_span("foo") as foo_span:
foo_span.add_event("Alpha")
foo_span.add_event("boom boom")
foo_span.set_attribute("phone", "iphone X")
foo_span.set_attribute("beats", "spotify")
with tracer.start_as_current_span("bar") as bar_span:
bar_span.add_event("Apocalypse")
bar_span.set_attribute("sky", "blue")
with tracer.start_as_current_span("baz") as baz_span:
baz_span.add_event("event 1")
baz_span.set_attribute('att1', 'att_val1')
print("done")