OTEL Auto-Instrumentation Link

Automatically configures OpenTelemetry auto-instrumentation for your application pods.

What This Link Does

When you link an external_source_code or image_base component to an OTEL component, Stacktic automatically:

Link Attributes

Attribute Required Description
otel_language Yes Language for auto-instrumentation: java, python, nodejs, dotnet, go
pythonpath For Python Required for Python apps. The working directory of your app (e.g., /usr/src/app)
otel_language_custom No Custom annotation key (overrides default instrumentation.opentelemetry.io/inject-{language})

Auto-Generated Configuration

1. Pod Annotation

metadata:
  annotations:
    instrumentation.opentelemetry.io/inject-python: "otel/otel-instrumentation"

2. Environment Variables (cloud.env)

OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector-collector.otel.svc.cluster.local:4318
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=http://otel-collector-collector.otel.svc.cluster.local:4318/v1/traces
OTEL_EXPORTER_OTLP_METRICS_ENDPOINT=http://otel-collector-collector.otel.svc.cluster.local:4318/v1/metrics
OTEL_SERVICE_NAME=my-app
PYTHONPATH=/usr/src/app  # Only for Python

3. Deployment env: section (Python only)

containers:
  - name: app
    env:
      - name: PYTHONPATH
        value: "/usr/src/app"
    envFrom:
      - secretRef:
          name: my-app-external-source-secrets

Why PYTHONPATH is Required for Python

The OTEL operator's Python auto-instrumentation has a known issue (GitHub #2495):

Solution: Set pythonpath attribute to your app's working directory (must match Dockerfile WORKDIR)

Why PYTHONPATH Must Be in env: (Not Secret)

The OTEL operator init container behavior:

That's why Stacktic generates PYTHONPATH in both places:

  1. cloud.env (secret) - For non-OTEL scenarios
  2. source_code.yaml (deployment env:) - For OTEL to work correctly

Supported Languages

otel_language Annotation Extra Config
java instrumentation.opentelemetry.io/inject-java None
python instrumentation.opentelemetry.io/inject-python Requires pythonpath attribute
nodejs instrumentation.opentelemetry.io/inject-nodejs None
dotnet instrumentation.opentelemetry.io/inject-dotnet None
go instrumentation.opentelemetry.io/inject-go None

Example Link Configuration

Python (Django/Flask/FastAPI)

Link: django -> otel
Attributes:
  otel_language: "python"
  pythonpath: "/usr/src/app"

Java (Spring Boot)

Link: backend -> otel
Attributes:
  otel_language: "java"

Node.js (Express/NestJS)

Link: api -> otel
Attributes:
  otel_language: "nodejs"

How to Find Your pythonpath Value

Check your Dockerfile for the WORKDIR directive:

# Dockerfile
FROM python:3.12-slim
WORKDIR /usr/src/app  # <-- This is your pythonpath
COPY . .
CMD ["python", "manage.py", "runserver"]

Common values:

Troubleshooting