-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_example.py
More file actions
56 lines (37 loc) · 1.31 KB
/
Copy pathbasic_example.py
File metadata and controls
56 lines (37 loc) · 1.31 KB
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
import sys
import os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import asyncio
import random
import time
from opentelemetry import trace
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from opentelemetry.sdk.trace import TracerProvider
# setup signoz exporter
from otel_pyautoinstrumentor import SysmonAutoInstrumentor
trace.set_tracer_provider(TracerProvider())
tracer = trace.get_tracer(__name__)
otlp_exporter = OTLPSpanExporter(
endpoint="http://localhost:4317",
insecure=True
)
trace.get_tracer_provider().add_span_processor(BatchSpanProcessor(otlp_exporter))
# setup python auto instrumentor
sysmon_autoinstumentor = SysmonAutoInstrumentor(tracer)
sysmon_autoinstumentor.instrument()
def main():
time.sleep(0.5)
main2()
def main2():
time.sleep(0.5)
asyncio.run(main5())
async def main4(random_times):
await asyncio.sleep(random_times)
async def main5():
random_times = [random.random() for _ in range(10)]
tasks = [asyncio.create_task(main4(random_time)) for random_time in random_times]
await asyncio.gather(*tasks)
main()
with tracer.start_as_current_span("root") as span:
main()