-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(example): add example to test context propagation (#4046)
- Loading branch information
1 parent
67a46f1
commit 1d837b4
Showing
17 changed files
with
3,242 additions
and
0 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
examples/testing-context-propagation/automatic-instrumentation/.gitignore
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 @@ | ||
.env |
43 changes: 43 additions & 0 deletions
43
examples/testing-context-propagation/automatic-instrumentation/README.md
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,43 @@ | ||
## Testing Context Propagation with Automatic Instrumentation | ||
|
||
### Overview | ||
|
||
This example demonstrates how to test context propagation with automatic instrumentation. It consists of a simple application that uses a backend service to store data. The application is instrumented with OpenTelemetry and sends traces to an Jaeger backend. | ||
|
||
```mermaid | ||
graph LR | ||
User -- POST /sendData --> ServiceA | ||
ServiceA -- POST /augmentData --> ServiceB | ||
``` | ||
|
||
### Requirements | ||
|
||
To run it you need: | ||
|
||
- [Docker](https://www.docker.com/get-started/) | ||
- [Tracetest CLI](https://docs.tracetest.io/getting-started/overview) | ||
|
||
You will need to have a Tracetest.io account and an environment to run this example. Once that you created it, add an `.env` file with the following content: | ||
|
||
```bash | ||
TRACETEST_ENVIRONMENT_ID=... | ||
TRACETEST_API_KEY=... | ||
``` | ||
|
||
You can get the values for both `TRACETEST_ENVIRONMENT_ID` and `TRACETEST_API_KEY` on the page: https://app.tracetest.io/retrieve-token | ||
|
||
### Running the Example | ||
|
||
After setting up the environment, you can run the example with the following commands: | ||
|
||
```bash | ||
docker compose up | ||
``` | ||
|
||
And to run the test you can execute the following commands: | ||
|
||
```bash | ||
tracetest configure ## connect to your environment | ||
|
||
tracetest apply datastore -f ./tracetest/tracing-backend.yaml | ||
``` |
86 changes: 86 additions & 0 deletions
86
examples/testing-context-propagation/automatic-instrumentation/docker-compose.yaml
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,86 @@ | ||
services: | ||
service-a: | ||
build: ./service-a | ||
command: | ||
- opentelemetry-instrument | ||
- python | ||
- flask_app.py | ||
extra_hosts: | ||
- "host.docker.internal:host-gateway" | ||
environment: | ||
- API_PORT=8800 | ||
- SERVICE_B_URL=http://service-b:8801 | ||
- OTEL_SERVICE_NAME=service-a | ||
- OTEL_TRACES_EXPORTER=otlp | ||
- OTEL_METRICS_EXPORTER=none | ||
- OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=http://otel-collector:4317 | ||
ports: | ||
- 8800:8800 | ||
depends_on: | ||
otel-collector: | ||
condition: service_started | ||
service-b: | ||
condition: service_started | ||
|
||
service-b: | ||
build: ./service-b | ||
command: | ||
- npm | ||
- start | ||
extra_hosts: | ||
- "host.docker.internal:host-gateway" | ||
environment: | ||
- API_PORT=8801 | ||
- OTEL_SERVICE_NAME=service-b | ||
- OTEL_TRACES_EXPORTER=otlp | ||
- OTEL_METRICS_EXPORTER=none | ||
- OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=http://otel-collector:4318/v1/traces | ||
- OTEL_NODE_DISABLED_INSTRUMENTATIONS="fs" | ||
ports: | ||
- 8801:8801 | ||
depends_on: | ||
otel-collector: | ||
condition: service_started | ||
|
||
# Observability stack | ||
otel-collector: | ||
command: | ||
- --config | ||
- /otel-local-config.yaml | ||
depends_on: | ||
jaeger: | ||
condition: service_started | ||
image: otel/opentelemetry-collector:0.108.0 | ||
ports: | ||
- 4317:4317 | ||
volumes: | ||
- ./observability/otelcollector.config.yaml:/otel-local-config.yaml | ||
|
||
jaeger: | ||
healthcheck: | ||
test: | ||
- CMD | ||
- wget | ||
- --spider | ||
- localhost:16686 | ||
timeout: 3s | ||
interval: 1s | ||
retries: 60 | ||
image: jaegertracing/all-in-one:latest | ||
restart: unless-stopped | ||
environment: | ||
- COLLECTOR_OTLP_ENABLED=true | ||
ports: | ||
- 16686:16686 | ||
- 16685:16685 | ||
|
||
# Cloud-based Managed Tracetest | ||
tracetest-agent: | ||
image: kubeshop/tracetest-agent:latest | ||
command: ["-v"] | ||
environment: | ||
# Get the required information here: https://app.tracetest.io/retrieve-token | ||
- TRACETEST_API_KEY=${TRACETEST_API_KEY} | ||
- TRACETEST_ENVIRONMENT_ID=${TRACETEST_ENVIRONMENT_ID} | ||
- TRACETEST_MODE=verbose | ||
|
27 changes: 27 additions & 0 deletions
27
...ing-context-propagation/automatic-instrumentation/observability/otelcollector.config.yaml
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,27 @@ | ||
receivers: | ||
otlp: | ||
protocols: | ||
grpc: | ||
endpoint: 0.0.0.0:4317 | ||
http: | ||
endpoint: 0.0.0.0:4318 | ||
|
||
processors: | ||
batch: | ||
timeout: 100ms | ||
|
||
exporters: | ||
debug: | ||
verbosity: detailed | ||
|
||
otlp/jaeger: | ||
endpoint: jaeger:4317 | ||
tls: | ||
insecure: true | ||
|
||
service: | ||
pipelines: | ||
traces: | ||
receivers: [otlp] | ||
processors: [batch] | ||
exporters: [debug, otlp/jaeger] |
172 changes: 172 additions & 0 deletions
172
examples/testing-context-propagation/automatic-instrumentation/service-a/.gitignore
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,172 @@ | ||
_venv | ||
.env | ||
|
||
node_modules | ||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
*.py,cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
cover/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
db.sqlite3-journal | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
.pybuilder/ | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# pyenv | ||
# For a library or package, you might want to ignore these files since the code is | ||
# intended to run in multiple environments; otherwise, check them in: | ||
# .python-version | ||
|
||
# pipenv | ||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. | ||
# However, in case of collaboration, if having platform-specific dependencies or dependencies | ||
# having no cross-platform support, pipenv may install dependencies that don't work, or not | ||
# install all needed dependencies. | ||
#Pipfile.lock | ||
|
||
# poetry | ||
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. | ||
# This is especially recommended for binary packages to ensure reproducibility, and is more | ||
# commonly ignored for libraries. | ||
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control | ||
#poetry.lock | ||
|
||
# pdm | ||
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. | ||
#pdm.lock | ||
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it | ||
# in version control. | ||
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control | ||
.pdm.toml | ||
.pdm-python | ||
.pdm-build/ | ||
|
||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm | ||
__pypackages__/ | ||
|
||
# Celery stuff | ||
celerybeat-schedule | ||
celerybeat.pid | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
# pytype static type analyzer | ||
.pytype/ | ||
|
||
# Cython debug symbols | ||
cython_debug/ | ||
|
||
# PyCharm | ||
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can | ||
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore | ||
# and can be added to the global gitignore or merged into this file. For a more nuclear | ||
# option (not recommended) you can uncomment the following to ignore the entire idea folder. | ||
#.idea/ | ||
node_modules/ | ||
/test-results/ | ||
/playwright-report/ | ||
/blob-report/ | ||
/playwright/.cache/ |
1 change: 1 addition & 0 deletions
1
examples/testing-context-propagation/automatic-instrumentation/service-a/.python-version
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 @@ | ||
3.12 |
9 changes: 9 additions & 0 deletions
9
examples/testing-context-propagation/automatic-instrumentation/service-a/Dockerfile
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,9 @@ | ||
FROM python:3.12.4-slim | ||
|
||
WORKDIR /opt/app | ||
COPY requirements.txt ./ | ||
|
||
RUN pip install --no-cache-dir -r requirements.txt | ||
RUN opentelemetry-bootstrap -a install | ||
|
||
COPY . . |
Oops, something went wrong.