-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathtelemetry.py
47 lines (37 loc) · 1.25 KB
/
telemetry.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
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace.export import (
BatchSpanProcessor,
)
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
def CreateTracer(service_name, trace_name, infrastackai_api_key=None):
tracer = trace.get_tracer(trace_name)
resource = Resource.create({"service.name": service_name})
provider = TracerProvider(resource=resource)
trace.set_tracer_provider(provider)
provider.add_span_processor(
BatchSpanProcessor(
OTLPSpanExporter(
endpoint="https://collector-us1-http.infrastack.ai/v1/traces",
headers=(("infrastack-api-key", infrastackai_api_key),),
)
)
)
return tracer
def os_name():
import platform
system_name = platform.system()
if system_name == "Windows":
return "Windows"
elif system_name == "Darwin":
return "macOS"
elif system_name == "Linux":
return "Linux"
else:
return "Unknown OS"
my_tracer = CreateTracer(
"gpt_computer_agent",
"app",
infrastackai_api_key="sk-2b29c6da910d2883de0599d4c5dd6b9d2e4ec61bbfa834d5",
)