blob: d72344c1253791a48ac7f19590032c9b1a27bc62 [file] [log] [blame]
Wei-Yu Chenad55cb82022-02-15 20:07:01 +08001# SPDX-FileCopyrightText: 2020 The Magma Authors.
2# SPDX-FileCopyrightText: 2022 Open Networking Foundation <support@opennetworking.org>
3#
4# SPDX-License-Identifier: BSD-3-Clause
Wei-Yu Chen49950b92021-11-08 19:19:18 +08005
6import os
7
8import sentry_sdk
9import snowflake
10from configuration.service_configs import get_service_config_value
11
12CONTROL_PROXY = 'control_proxy'
13SENTRY_URL = 'sentry_url_python'
14SENTRY_SAMPLE_RATE = 'sentry_sample_rate'
15COMMIT_HASH = 'COMMIT_HASH'
16HWID = 'hwid'
17SERVICE_NAME = 'service_name'
18
19
20def sentry_init(service_name: str):
21 """Initialize connection and start piping errors to sentry.io."""
22 sentry_url = get_service_config_value(
23 CONTROL_PROXY,
24 SENTRY_URL,
25 default='',
26 )
27 if not sentry_url:
28 return
29
30 sentry_sample_rate = get_service_config_value(
31 CONTROL_PROXY,
32 SENTRY_SAMPLE_RATE,
33 default=1.0,
34 )
35 sentry_sdk.init(
36 dsn=sentry_url,
37 release=os.getenv(COMMIT_HASH),
38 traces_sample_rate=sentry_sample_rate,
39 )
40 sentry_sdk.set_tag(HWID, snowflake.snowflake())
41 sentry_sdk.set_tag(SERVICE_NAME, service_name)