-
Notifications
You must be signed in to change notification settings - Fork 383
Expand file tree
/
Copy pathsdk_usage.py
More file actions
35 lines (29 loc) · 906 Bytes
/
sdk_usage.py
File metadata and controls
35 lines (29 loc) · 906 Bytes
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
import sys
import splunklib
from .metric import Metric, MetricType
from .sender import TelemetrySender
import logging
from splunklib import setup_logging
setup_logging(logging.DEBUG)
log = logging.getLogger()
SDK_USAGE_COMPONENT = "splunk.sdk.usage"
# FIXME: adding Service typehint produces circular dependency
def log_telemetry_sdk_usage(service, **kwargs):
metric = Metric(
MetricType.Event,
SDK_USAGE_COMPONENT,
{
"sdk-language": "python",
"python-version": sys.version,
"sdk-version": splunklib.__version__,
**kwargs,
},
4,
)
try:
log.debug(f"sending new telemetry {metric}")
telemetry = TelemetrySender(service)
# TODO: handle possible errors
_, _ = telemetry.send(metric)
except Exception as e:
log.error("Could not send telemetry", exc_info=True)