-
Notifications
You must be signed in to change notification settings - Fork 1
Add opentelemetry support #67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,12 @@ | |
| "REQUEST_MAX_SIZE": 100000000, | ||
| "CACHE_MAX_AGE": 604800 | ||
| }, | ||
| "opentelemetry": { | ||
| "OPENTELEMETRY_ENABLED": false, | ||
| "OPENTELEMETRY_SERVICE_NAME": "biothings-annotator", | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you confirm the Service Name to Chunlei? If it's different from |
||
| "OPENTELEMETRY_JAEGER_HOST": "http://localhost", | ||
| "OPENTELEMETRY_JAEGER_PORT": 6381 | ||
| }, | ||
| "extension": { | ||
| "openapi": { | ||
| "OAS": true, | ||
|
|
||
| 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) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,7 +52,13 @@ tests = [ | |
| "sanic-testing >= 24.6.0", | ||
| "pytest-randomly" | ||
| ] | ||
|
|
||
| telemetry = [ | ||
| "opentelemetry-api >= 1.28.2", | ||
| "opentelemetry-sdk >= 1.28.2", | ||
| "opentelemetry-exporter-otlp >= 1.28.2", | ||
| "opentelemetry.exporter.jaeger.thrift >= 1.21.0", | ||
| "opentelemetry-instrumentation >= 0.49b2" | ||
| ] | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey @ctrl-schaff, while running the branch locally, there is the error below. It seems the library just needs to be installed. However, they are here to be installed. |
||
|
|
||
| [project.urls] | ||
| "Homepage" = "https://github.com/biothings/biothings_annotator" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool to have the default values here.
We could just enable the OPTL in the Dockerfile as an ENV variable