Skip to content

Add a traceparent annotation to the TestRun created by v1alpha #112

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions python/src/etos_api/routers/v1alpha/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
from etos_lib.kubernetes import TestRun, Environment, Kubernetes
from fastapi import FastAPI, HTTPException
from starlette.responses import Response
from opentelemetry import trace
from opentelemetry import trace, context
from opentelemetry.propagate import inject
from opentelemetry.trace import Span


Expand Down Expand Up @@ -105,6 +106,18 @@ async def health_check():
return Response(status_code=204)


def get_current_context() -> str:
"""Get the current OpenTelemetry context."""
ctx = context.get_current()
LOGGER.info("Current OpenTelemetry context: %s", ctx)
carrier = {}
# inject() creates a dict with context reference,
# e. g. {'traceparent': '00-0be6c260d9cbe9772298eaf19cb90a5b-371353ee8fbd3ced-01'}
inject(carrier)
env = ",".join(f"{k}={v}" for k, v in carrier.items())
return env


async def _create_testrun(etos: StartTestrunRequest, span: Span) -> dict:
"""Create a testrun for ETOS to execute.

Expand Down Expand Up @@ -197,20 +210,25 @@ async def _create_testrun(etos: StartTestrunRequest, span: Span) -> dict:
"etos.eiffel-community.github.io/id": testrun_id,
"etos.eiffel-community.github.io/cluster": os.getenv("ETOS_CLUSTER", "Unknown"),
},
annotations={
"etos.eiffel-community.github.io/traceparent": get_current_context(),
},
),
spec=TestRunSpec(
cluster=os.getenv("ETOS_CLUSTER", "Unknown"),
id=testrun_id,
retention=retention,
suiteRunner=Image(
image=os.getenv(
"SUITE_RUNNER_IMAGE", "registry.nordix.org/eiffel/etos-suite-runner:latest"
"SUITE_RUNNER_IMAGE",
"registry.nordix.org/eiffel/etos-suite-runner:latest",
),
imagePullPolicy=os.getenv("SUITE_RUNNER_IMAGE_PULL_POLICY", "IfNotPresent"),
),
logListener=Image(
image=os.getenv(
"LOG_LISTENER_IMAGE", "registry.nordix.org/eiffel/etos-log-listener:latest"
"LOG_LISTENER_IMAGE",
"registry.nordix.org/eiffel/etos-log-listener:latest",
),
imagePullPolicy=os.getenv("LOG_LISTENER_IMAGE_PULL_POLICY", "IfNotPresent"),
),
Expand Down
Loading