-
Notifications
You must be signed in to change notification settings - Fork 0
PB-1447: Improve tracing #87
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b90a78c
PB-1447: Enable local telemetry
msom a13e5e8
PB-1447: Remove elastic-opentelemetry package
msom 326b452
PB-1447: Document trace sampling
msom b173294
PB-1447: Add opentelemetry-instrumentation-logging
msom 1d716ee
PB-1447: Remove opentelemetry-instrumentation-requests
msom 4c560cd
PB-1447: Add tracing flags
msom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,25 +1,56 @@ | ||
| import os | ||
| from os import getenv | ||
|
|
||
| from opentelemetry import trace | ||
| from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import \ | ||
| OTLPSpanExporter | ||
| from opentelemetry.instrumentation.botocore import BotocoreInstrumentor | ||
| from opentelemetry.instrumentation.flask import FlaskInstrumentor | ||
| from opentelemetry.instrumentation.logging import LoggingInstrumentor | ||
| from opentelemetry.sdk.resources import Resource | ||
| from opentelemetry.sdk.trace import TracerProvider | ||
| from opentelemetry.sdk.trace.export import BatchSpanProcessor | ||
|
|
||
| from app.helpers.utils import strtobool | ||
|
|
||
| def strtobool(value) -> bool: | ||
| """Convert a string representation of truth to true (1) or false (0). | ||
| True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values | ||
| are 'n', 'no', 'f', 'false', 'off', and '0'. Raises ValueError if | ||
| 'val' is anything else. | ||
| """ | ||
| value = value.lower() | ||
| if value in ('y', 'yes', 't', 'true', 'on', '1'): | ||
| return True | ||
| if value in ('n', 'no', 'f', 'false', 'off', '0'): | ||
| return False | ||
| raise ValueError(f"invalid truth value \'{value}\'") | ||
|
|
||
| def setup_trace_provider(worker_pid): | ||
| trace.set_tracer_provider(TracerProvider(resource=Resource.create())) | ||
|
|
||
| # Since we created a new tracer, the default span processor is gone. We need to | ||
| # create a new one using the default OTEL env variables and ad it to the tracer. | ||
| span_processor = BatchSpanProcessor( | ||
| OTLPSpanExporter( | ||
| endpoint=os.getenv('OTEL_EXPORTER_OTLP_ENDPOINT', "http://localhost:4317"), | ||
| headers=os.getenv('OTEL_EXPORTER_OTLP_HEADERS'), | ||
| insecure=strtobool(os.getenv('OTEL_EXPORTER_OTLP_INSECURE', "false")) | ||
| def initialize() -> None: | ||
| if not strtobool(getenv("OTEL_SDK_DISABLED", "false")): | ||
| if strtobool(getenv("OTEL_ENABLE_BOTO", "false")): | ||
| BotocoreInstrumentor().instrument() | ||
| if strtobool(getenv("OTEL_ENABLE_LOGGING", "false")): | ||
| LoggingInstrumentor().instrument() | ||
|
|
||
|
|
||
| def initialize_flask(app): | ||
| if not strtobool(getenv("OTEL_SDK_DISABLED", "false")): | ||
| if strtobool(getenv("OTEL_ENABLE_FLASK", "false")): | ||
| FlaskInstrumentor().instrument_app(app) | ||
|
|
||
|
|
||
| def setup_trace_provider(): | ||
| if not strtobool(getenv("OTEL_SDK_DISABLED", "false")): | ||
| # Since we created a new tracer, the default span processor is gone. We need to | ||
| # create a new one using the default OTEL env variables and ad it to the tracer. | ||
| span_processor = BatchSpanProcessor( | ||
| OTLPSpanExporter( | ||
| endpoint=getenv('OTEL_EXPORTER_OTLP_ENDPOINT', "http://localhost:4317"), | ||
| headers=getenv('OTEL_EXPORTER_OTLP_HEADERS'), | ||
| insecure=strtobool(getenv('OTEL_EXPORTER_OTLP_INSECURE', "false")) | ||
| ) | ||
| ) | ||
| ) | ||
| trace.get_tracer_provider().add_span_processor(span_processor) | ||
|
|
||
| provider = TracerProvider(resource=Resource.create()) | ||
| provider.add_span_processor(span_processor) | ||
| trace.set_tracer_provider(provider) |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,21 @@ | ||
| receivers: | ||
| otlp: | ||
| protocols: | ||
| grpc: | ||
| endpoint: 0.0.0.0:4317 | ||
|
|
||
| processors: | ||
| batch: | ||
|
|
||
| exporters: | ||
| debug: | ||
| verbosity: detailed | ||
| zipkin: | ||
| endpoint: http://zipkin:9411/api/v2/spans | ||
|
|
||
| service: | ||
| pipelines: | ||
| traces: | ||
| receivers: [otlp] | ||
| processors: [batch] | ||
| exporters: [debug, zipkin] |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Maybe this is an argument to use jaeger instead of zipkin?
You don't need an extra step to configure a OTEL collector when you use jaeger?
https://github.com/geoadmin/service-wms/pull/728/files#r2707189580