-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial instrumentation for the opentelemetry support
- Loading branch information
jschaff
committed
Dec 3, 2024
1 parent
562033e
commit 4698e84
Showing
4 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
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,40 @@ | ||
""" | ||
Integrates opentelemetry tracing with the biothings-annotator | ||
web service | ||
""" | ||
|
||
import opentelemetry | ||
from opentelemetry.exporter.jaeger.thrift import JaegerExporter | ||
from opentelemetry.sdk.resources import SERVICE_NAME, Resource | ||
from opentelemetry.sdk.trace import TracerProvider | ||
from opentelemetry.sdk.trace.export import BatchSpanProcessor | ||
import sanic | ||
from tracing import instrument_app | ||
|
||
|
||
def instrument_application_telemetry(application_instance: sanic.Sanic): | ||
""" | ||
Method integrating the opentelemetry into the annotator | ||
web service | ||
""" | ||
opentelemetry_configuration = application_instance.config.get("opentelemetry", {}) | ||
opentelemetry_enabled = opentelemetry_configuration.get("OPENTELEMETRY_ENABLED", False) | ||
|
||
if opentelemetry_enabled: | ||
opentelemetry_jaeger_host = opentelemetry_configuration["OPENTELEMETRY_JAEGER_HOST"] | ||
opentelemetry_jaeger_port = opentelemetry_configuration["OPENTELEMETRY_JAEGER_PORT"] | ||
opentelemetry_service_name = opentelemetry_configuration["OPENTELEMETRY_SERVICE_NAME"] | ||
|
||
jaeger_trace_exporter = JaegerExporter( | ||
agent_host_name=opentelemetry_jaeger_host, | ||
agent_port=opentelemetry_jaeger_port, | ||
udp_split_oversized_batches=True, | ||
) | ||
service_resource = Resource.create({SERVICE_NAME: opentelemetry_service_name}) | ||
|
||
trace_provider = TracerProvider(resource=service_resource) | ||
batch_span_processor = BatchSpanProcessor(jaeger_trace_exporter) | ||
trace_provider.add_span_processor(batch_span_processor) | ||
opentelemetry.trace.set_tracer_provider(trace_provider) | ||
tracer = opentelemetry.trace.get_tracer("biothings-annotator") | ||
instrument_app(application_instance, tracer) |
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