forked from aws-observability/aws-otel-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplication.py
69 lines (50 loc) · 1.91 KB
/
application.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0
# OTel Imports
from opentelemetry import propagate, trace
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import (
OTLPSpanExporter,
)
# Instrumentation Libraries
from opentelemetry.instrumentation.botocore import BotocoreInstrumentor
from opentelemetry.instrumentation.flask import FlaskInstrumentor
from opentelemetry.instrumentation.requests import RequestsInstrumentor
# OpenTelemetry SDK Components
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
# AWS X-Ray Propagator Components
from opentelemetry.propagators.aws import AwsXRayPropagator
# AWS X-Ray SDK Extension Components
from opentelemetry.sdk.extension.aws.trace import AwsXRayIdGenerator
# from opentelemetry.sdk.resources import get_aggregated_resources
# from opentelemetry.sdk.extension.aws.resource.ec2 import (
# AwsEc2ResourceDetector,
# )
# Integration Test App
from create_flask_app import app, get_flask_app_run_args
# Setup AWS X-Ray Propagator
# Propagators can be set using environment variable: OTEL_PROPAGATORS = xray
propagate.set_global_textmap(AwsXRayPropagator())
# Setup Tracer
# OTLP Exporter is configured through environment variables:
# - OTEL_EXPORTER_OTLP_ENDPOINT
# - OTEL_EXPORTER_OTLP_CERTIFICATE
otlp_exporter = OTLPSpanExporter()
span_processor = BatchSpanProcessor(otlp_exporter)
trace.set_tracer_provider(
TracerProvider(
active_span_processor=span_processor,
id_generator=AwsXRayIdGenerator(),
# resource=get_aggregated_resources(
# [
# AwsEc2ResourceDetector(),
# ]
# ),
)
)
# Instrument Packages
BotocoreInstrumentor().instrument()
FlaskInstrumentor().instrument_app(app)
RequestsInstrumentor().instrument()
if __name__ == "__main__":
app.run(**get_flask_app_run_args())