Skip to content

Commit

Permalink
feat(otel): add otel support (#476)
Browse files Browse the repository at this point in the history
* feat(otel): add otel support  close #458
  • Loading branch information
wklken authored and EmilyMei committed Jun 15, 2022
1 parent 5e0a835 commit fb68ca8
Show file tree
Hide file tree
Showing 17 changed files with 1,978 additions and 100 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ venv/
ENV/
env.bak/
venv.bak/
.envrc

# Spyder project settings
.spyderproject
Expand Down Expand Up @@ -233,4 +234,7 @@ deploy/helm/login/templates/c_*.*
deploy/helm/bk-user-stack/templates/c_*.*

# local hooks
pre_commit_hooks
pre_commit_hooks

# local settings
cliff.toml
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,16 @@ follow_imports="skip"
show_error_codes = true
strict_optional=true
pretty=true
exclude = '''(?x)(
instrumentor\.py$
| otel\.py$
)'''

[[tool.mypy.overrides]]
module = [
"*.migrations.*",
"*.config.*",
"bkuser_sdk.*",
"*.bkuser_sdk.*"
"*.bkuser_sdk.*",
]
ignore_errors = true
12 changes: 12 additions & 0 deletions src/api/bkuser_core/config/common/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@
# ==============================================================================
SENTRY_DSN = env("SENTRY_DSN", default="")

# ==============================================================================
# OTEL
# ==============================================================================
# tracing: otel 相关配置
# if enable, default false
ENABLE_OTEL_TRACE = env.bool("BKAPP_ENABLE_OTEL_TRACE", default=False)
BKAPP_OTEL_INSTRUMENT_DB_API = env.bool("BKAPP_OTEL_INSTRUMENT_DB_API", default=True)
BKAPP_OTEL_SERVICE_NAME = env("BKAPP_OTEL_SERVICE_NAME", default="bk-user")
BKAPP_OTEL_SAMPLER = env("BKAPP_OTEL_SAMPLER", default="parentbased_always_off")
BKAPP_OTEL_BK_DATA_ID = env.int("BKAPP_OTEL_BK_DATA_ID", default=-1)
BKAPP_OTEL_GRPC_HOST = env("BKAPP_OTEL_GRPC_HOST", default="")

# ==============================================================================
# 全局应用配置
# ==============================================================================
Expand Down
18 changes: 15 additions & 3 deletions src/api/bkuser_core/monitoring/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,25 @@
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
"""
from celery.signals import worker_process_init
from django.apps import AppConfig

from .sentry import init_sentry_sdk
from bkuser_global.tracing.otel import setup_by_settings
from bkuser_global.tracing.sentry import init_sentry_sdk


class MonitoringConfig(AppConfig):
name = 'bkuser_core.monitoring'
name = "bkuser_core.monitoring"

def ready(self):
init_sentry_sdk()
init_sentry_sdk("bk-user-api", django_integrated=True, redis_integrated=True, celery_integrated=True)


@worker_process_init.connect(weak=False)
def worker_process_init_otel_trace_setup(*args, **kwargs):
setup_by_settings()


@worker_process_init.connect(weak=False)
def worker_process_init_sentry_setup(*args, **kwargs):
init_sentry_sdk()
Loading

0 comments on commit fb68ca8

Please sign in to comment.