-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for Opentelemetry Tracing. Programmatic instrumentation of Fl…
…ask, SQLAlchemy, and Requests libraries (#118) Signed-off-by: Mike Kingsbury <[email protected]>
- Loading branch information
1 parent
287e913
commit 0e3313d
Showing
6 changed files
with
451 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# SPDX-License-Identifier: GPL-2.0+ | ||
|
||
from opentelemetry import trace | ||
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter | ||
from opentelemetry.instrumentation.flask import FlaskInstrumentor | ||
from opentelemetry.instrumentation.requests import RequestsInstrumentor | ||
from opentelemetry.instrumentation.sqlalchemy import SQLAlchemyInstrumentor | ||
from opentelemetry.sdk.resources import SERVICE_NAME, Resource | ||
from opentelemetry.sdk.trace import TracerProvider | ||
from opentelemetry.sdk.trace.export import BatchSpanProcessor | ||
|
||
|
||
def setup_tracing(app): # pragma: no cover | ||
endpoint = app.config.get("OTEL_EXPORTER_OTLP_METRICS_ENDPOINT") | ||
service_name = app.config.get("OTEL_EXPORTER_SERVICE_NAME") | ||
if not endpoint or not service_name: | ||
return | ||
resource = Resource(attributes={SERVICE_NAME: service_name}) | ||
provider = TracerProvider(resource=resource) | ||
instrumentor = FlaskInstrumentor() | ||
instrumentor.instrument_app(app) | ||
SQLAlchemyInstrumentor().instrument( | ||
enable_commenter=True, | ||
commenter_options={ | ||
"db_driver": True, | ||
}, | ||
) | ||
RequestsInstrumentor().instrument() | ||
otlp_exporter = OTLPSpanExporter(endpoint=app.config["OTEL_EXPORTER_OTLP_METRICS_ENDPOINT"]) | ||
processor = BatchSpanProcessor(otlp_exporter) | ||
# processor = BatchSpanProcessor(ConsoleSpanExporter()) | ||
provider.add_span_processor(processor) | ||
trace.set_tracer_provider(provider) |