feat: add .NET auto-instrumentation script

This commit is contained in:
2026-02-06 19:18:49 -03:00
parent 6038e82b22
commit 0cd8b96cd0
3 changed files with 120 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
FROM mcr.microsoft.com/dotnet/runtime:8.0 AS base
# Download OpenTelemetry .NET auto-instrumentation
RUN apt-get update && apt-get install -y curl unzip && \
curl -sSL https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/releases/download/v1.7.0/opentelemetry-dotnet-instrumentation-linux-glibc-x64.zip -o /tmp/otel.zip && \
unzip /tmp/otel.zip -d /opt/otel-dotnet && \
rm /tmp/otel.zip && \
chmod -R 755 /opt/otel-dotnet
# Create volume for sharing instrumentation files
VOLUME /otel-dotnet
CMD ["cp", "-r", "/opt/otel-dotnet/.", "/otel-dotnet/"]

View File

@@ -0,0 +1,43 @@
# Add this to your existing docker-compose.yml to enable .NET tracing
#
# Usage:
# 1. Add the otel-init service
# 2. Add environment variables and volumes to your .NET app
# 3. Set OTEL_SERVICE_NAME for each service
services:
# Init container that provides OpenTelemetry .NET instrumentation
otel-init:
build:
context: .
dockerfile: Dockerfile
volumes:
- otel-dotnet:/otel-dotnet
restart: "no"
# Example: Your .NET app with tracing enabled
# my-dotnet-app:
# image: your-image:tag
# depends_on:
# otel-init:
# condition: service_completed_successfully
# environment:
# # OpenTelemetry config
# - OTEL_SERVICE_NAME=my-dotnet-app
# - OTEL_EXPORTER_OTLP_ENDPOINT=http://ophion:8080
# - OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
# - OTEL_TRACES_EXPORTER=otlp
# - OTEL_METRICS_EXPORTER=otlp
# - OTEL_LOGS_EXPORTER=otlp
# # .NET CLR profiler config
# - CORECLR_ENABLE_PROFILING=1
# - CORECLR_PROFILER={918728DD-259F-4A6A-AC2B-B85E1B658571}
# - CORECLR_PROFILER_PATH=/otel-dotnet/linux-x64/OpenTelemetry.AutoInstrumentation.Native.so
# - DOTNET_ADDITIONAL_DEPS=/otel-dotnet/AdditionalDeps
# - DOTNET_SHARED_STORE=/otel-dotnet/store
# - DOTNET_STARTUP_HOOKS=/otel-dotnet/net/OpenTelemetry.AutoInstrumentation.StartupHook.dll
# volumes:
# - otel-dotnet:/otel-dotnet:ro
volumes:
otel-dotnet: