一键导入
dtwiz-otel
// Guidance for implementing OpenTelemetry auto-instrumentation for various runtimes in dtwiz
// Guidance for implementing OpenTelemetry auto-instrumentation for various runtimes in dtwiz
How dtwiz discovers, identifies, and correlates running OS processes to project directories across Unix and Windows
Deploy Dynatrace observability with dtwiz — analyze systems, get ranked recommendations, and install monitoring (OneAgent, Kubernetes, Docker, OTel, AWS, Azure, GCP). Use when the user wants to set up, manage, or ingest data into Dynatrace monitoring. Covers ingesting metrics, logs, and traces from AWS, Azure, GCP, Kubernetes, containers, or hosts into Dynatrace via dtwiz.
| name | dtwiz-otel |
| description | Guidance for implementing OpenTelemetry auto-instrumentation for various runtimes in dtwiz |
You are assisting with development on dtwiz's OpenTelemetry support. This means downloading the OTel Collector binary, auto-instrumenting one or more running apps (Java, Python, Node.js, Go), and watching Dynatrace for ingested data.
See AGENTS.md for general Go development guidelines.
pkg/installer/
otel.go # Top-level OTel install orchestrator
otel_collector.go # Collector binary download + lifecycle
otel_env.go # OTEL_* env var generation (shared)
otel_java*.go # Java auto-instrumentation (3 files)
otel_python.go # Python auto-instrumentation
otel_nodejs*.go # Node.js auto-instrumentation
otel_go.go # Go (manual SDK instructions only)
otel_process.go # ManagedProcess: launch, port-detect, lifecycle
otel_runtime_scan.go # Project directory scanning
otel_runtime_scan_unix.go # Unix process detection
otel_runtime_scan_windows.go # Windows process detection
otel_uninstall.go # Uninstall orchestrator
ingest_watch.go # Post-install DQL polling loop
otel.go)InstallOtelCollectorWithProject()
├── Validate DT credentials (DT_ENVIRONMENT + DT_ACCESS_TOKEN or DT_PLATFORM_TOKEN)
├── prepareCollectorPlan() — download binary, generate config, find running collectors
├── detectAvailableRuntimes() — check for Python, Java, Node.js, Go on PATH
├── detectAllProjects() — parallel scan across enabled runtimes
├── User selects project → createRuntimePlan() → runtime-specific plan
├── Display plan preview (PrintPlanSteps)
├── User confirmation (confirmProceed)
├── Execute plan (start collector + instrument app)
└── WatchIngest() — poll DQL until user exits
Each runtime (Java, Python, Node.js, Go) implements the same interface:
pom.xml, requirements.txt, package.json)detectProcesses())buildXxxInstrumentationPlan() → collects entrypoints, prepares env varsRuntime(), PrintPlanSteps(), Execute()Process detection is OS-specific (see AGENTS.md); each runtime has its own heuristics for identifying and enriching running processes (e.g., javaDescendantPort() for Maven/Gradle wrappers).
otel_process.go)ManagedProcess tracks a launched subprocess: PID, detected ports, logs, exit status. Use StartManagedProcess() to launch; PrintProcessSummary() polls for port detection with timeout. Shared across all runtimes.
detectAvailableRuntimes() determines which runtimes are available by default.
Feature flag: DTWIZ_ALL_RUNTIMES / --all-runtimes enables all runtimes (Java and Go are gated by default).
// Credentials — never written to disk
DT_ENVIRONMENT // e.g. https://abc123.live.dynatrace.com
DT_ACCESS_TOKEN // Classic API token (dt0c01.*)
DT_PLATFORM_TOKEN // Platform API token (dt0s16.*)
// OTel env vars injected into instrumented processes
OTEL_SERVICE_NAME
OTEL_EXPORTER_OTLP_ENDPOINT // DT ingest URL
OTEL_EXPORTER_OTLP_HEADERS // Authorization: Api-Token ...
OTEL_EXPORTER_OTLP_PROTOCOL // http/protobuf
OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE // delta
See otel_env.go for the shared env var builder. Runtime-specific additions (Python logging, Node resource detectors) live in each runtime's file.
otel.tmpl template with DT endpoint + auth header./opentelemetry/config.yaml; binary to ./opentelemetry/ManagedProcessotel_uninstall.go)Heuristic-based, best-effort cleanup:
~/.opentelemetry/, ./opentelemetry/)// otel_xxx_unix_test.go
//go:build !windows
// otel_xxx_windows_test.go
//go:build windows
Use build tag //go:build integration for tests requiring external services or real binaries.
Prefer isolation strategies over global installations — use virtual environments, local package directories, and user-level paths rather than system-wide package managers. Current examples:
.venv/; OTel packages and project deps installed there.otel/ directory with its own package.json and node_modules/; never touches the project's own node_modules/~/.opentelemetry/java/; no packages installed; injected via -javaagent: flag or JAVA_TOOL_OPTIONS env varNever write secrets to disk. OTEL_EXPORTER_OTLP_HEADERS contains the API token — always pass it via cmd.Env at process launch, never embed it in generated scripts or config files.
Fail fast on missing prerequisites. Check required artifacts exist before doing any work (e.g., node_modules/ for Node.js, .output/server/index.mjs for Nuxt). Emit an actionable error pointing the user to the fix.
http/protobuf OTLP protocol (Dynatrace requirement)WatchIngest() is always the final step after instrumentation; don't skip itjavaDescendantPort() has Unix and Windows implementations)Execute()OTEL_SERVICE_NAME is per-entrypoint — when a project has multiple entrypoints, each gets a distinct service name