-
Notifications
You must be signed in to change notification settings - Fork 2
PB-2183: implement otel instrumentation #137
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # OTEL | ||
| OTEL_SDK_DISABLED=false | ||
| OTEL_ENABLE_FLASK=true | ||
| OTEL_ENABLE_LOGGING=true | ||
| OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4317 | ||
| OTEL_EXPORTER_OTLP_INSECURE=true | ||
| OTEL_RESOURCE_ATTRIBUTES=service.name=service-alti | ||
| OTEL_PYTHON_EXCLUDED_URLS="" | ||
| OTEL_PYTHON_LOG_CORRELATION=true |
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 |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| from os import getenv | ||
|
|
||
| from opentelemetry import trace | ||
| from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import \ | ||
| OTLPSpanExporter | ||
| 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.helpers import strtobool | ||
|
|
||
|
|
||
| def initialize() -> None: | ||
| if not strtobool(getenv("OTEL_SDK_DISABLED", "false")): | ||
| 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")) | ||
| ) | ||
| ) | ||
|
|
||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| version: "2" | ||
| services: | ||
| service-alti: | ||
| build: . | ||
| environment: | ||
| - HTTP_PORT=8080 | ||
| - LOGS_DIR=/logs | ||
| - DTM_BASE_PATH=/var/local/profile | ||
| env_file: | ||
| - .env.test | ||
| ports: | ||
| - "8080:8080" | ||
| volumes: | ||
| - ./logs:/logs | ||
| - /var/local/profile:/var/local/profile | ||
| depends_on: | ||
| - otel-collector | ||
|
|
||
| otel-collector: | ||
| image: otel/opentelemetry-collector-contrib:latest | ||
| command: --config otel-local-config.yaml | ||
| volumes: | ||
| - ./otel-local-config.yaml:/otel-local-config.yaml | ||
| ports: | ||
| - "4317:4317" | ||
|
|
||
| zipkin: | ||
| image: openzipkin/zipkin:latest | ||
| ports: | ||
| - "9411:9411" |
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
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.
Uh oh!
There was an error while loading. Please reload this page.