1. Tương thích

  • .NET SDK 6+
  • .NET Framework 4.6+ (Kiến trúc bộ xử lý được hỗ trợ: x86, AMD64 (x86-64), ARM64)

2. Windows (PowerShell)

# Download the module
$module_url = "https://minio-si-monitoring-gui.vnpt.vn/browser/agent/open-telemetry%2F"
$download_path = Join-Path $env:temp "OpenTelemetry.DotNet.Auto.psm1"
Invoke-WebRequest -Uri $module_url -OutFile $download_path -UseBasicParsing

# Import the module 
Import-Module $download_path

# Cài đặt OpenTelemetryCore
Install-OpenTelemetryCore   # Cài đặt trực tuyến
Install-OpenTelemetryCore -LocalPath "C:\Path\To\OpenTelemetry.zip" # Cài đặt nếu đã có sẵn trên máy


# [SIGNALS] đại diện cho 3 loại tín hiệu TRACES, LOGS và METRICS
# Cài đặt biến môi trường cho việc giám sát với phiên PowerShell hiện tại
$env:OTEL_[SIGNALS]_EXPORTER = "console"

# Cài đặt tự động theo dõi tín hiệu
$env:OTEL_DOTNET_AUTO_[SIGNALS]_ENABLED="true"

# [Signals] đại diện cho 3 loại tín hiệu: logs, metrics và traces
$env:OTEL_DOTNET_AUTO_[SIGNALS]_ENABLED="true"
$env:OTEL_EXPORTER_OTLP_[SIGNALS]_ENDPOINT = "your_signal_endpoint"
$env:OTEL_EXPORTER_OTLP_[SIGNALS]_HEADERS = "Authorization=<your_token>"
Register-OpenTelemetryForCurrentSession -OTelServiceName "OrderApp"

# Chạy ứng dụng
.\OrderApp.exe

Lưu ý: PowerShell phải được chạy với quyền Administrator và phiên bản tối thiểu là 5.1

3. .NET Framework triển khai trên IIS

# Download the module
$module_url = "https://minio-si-monitoring-gui.vnpt.vn/browser/agent/open-telemetry%2F"
$download_path = Join-Path $env:temp "OpenTelemetry.DotNet.Auto.psm1"
Invoke-WebRequest -Uri $module_url -OutFile $download_path -UseBasicParsing

# Import the module 
Import-Module $download_path

# Cài đặt OpenTelemetryCore
Install-OpenTelemetryCore   # Cài đặt trực tuyến
Install-OpenTelemetryCore -LocalPath "C:\Path\To\OpenTelemetry.zip" 

Register-OpenTelemetryForIIS

# === ĐƯỜNG DẪN OTel ===
$otelHome = "D:\dotnet\opentelemetry-dotnet-instrumentation-windows"
$otelDll  = "$otelHome\win-x64\OpenTelemetry.AutoInstrumentation.Native.dll"

# === KÍCH HOẠT PROFILER CHO .NET FRAMEWORK (IIS) ===
[Environment]::SetEnvironmentVariable("COR_ENABLE_PROFILING", "1", "Machine")
[Environment]::SetEnvironmentVariable("COR_PROFILER", "{918728DD-259F-4A6A-AC2B-E7F02DD23BDE}", "Machine")
[Environment]::SetEnvironmentVariable("COR_PROFILER_PATH", $otelDll, "Machine")
[Environment]::SetEnvironmentVariable("OTEL_DOTNET_AUTO_HOME", $otelHome, "Machine")

# === THÔNG TIN DỊCH VỤ ===
[Environment]::SetEnvironmentVariable("OTEL_SERVICE_NAME", "your_app_name", "Machine")
[Environment]::SetEnvironmentVariable("OTEL_RESOURCE_ATTRIBUTES", "deployment.environment=prod,service.version=1.0.0", "Machine")

# === ĐỊNH DẠNG GỬI DỮ LIỆU ===
[Environment]::SetEnvironmentVariable("OTEL_EXPORTER_OTLP_PROTOCOL", "http/protobuf", "Machine")

# === TRACES ===
[Environment]::SetEnvironmentVariable("OTEL_TRACES_EXPORTER", "otlp", "Machine")
[Environment]::SetEnvironmentVariable("OTEL_DOTNET_AUTO_TRACES_ENABLED", "true", "Machine")
[Environment]::SetEnvironmentVariable("OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", "yoru_endpoint", "Machine")
[Environment]::SetEnvironmentVariable("OTEL_EXPORTER_OTLP_TRACES_HEADERS", "Authorization=your_token", "Machine")

# === METRICS ===
[Environment]::SetEnvironmentVariable("OTEL_METRICS_EXPORTER", "otlp", "Machine")
[Environment]::SetEnvironmentVariable("OTEL_DOTNET_AUTO_METRICS_ENABLED", "true", "Machine")
[Environment]::SetEnvironmentVariable("OTEL_EXPORTER_OTLP_METRICS_ENDPOINT", "yoru_endpoint", "Machine")
[Environment]::SetEnvironmentVariable("OTEL_EXPORTER_OTLP_METRICS_HEADERS", "Authorization=your_token", "Machine")

# === ÁP DỤNG CẤU HÌNH CHO IIS ===
iisreset

Cần phải reset IIS

4. Linux and macOS

# Download the bash script
curl -sSfL https://minio-si-monitoring-gui.vnpt.vn/browser/agent/open-telemetry/otel-dotnet-auto-install.sh -O

# Install core files
sh ./otel-dotnet-auto-install.sh

# Kích hoạt script instrumentation
chmod +x $HOME/.otel-dotnet-auto/instrument.sh

# Cài đặt giám sát cho phiên shell hiện tại 
. $HOME/.otel-dotnet-auto/instrument.sh

export OTEL_TRACES_EXPORTER="console"
export OTEL_METRICS_EXPORTER="console"
export OTEL_LOGS_EXPORTER="console"

# Kích hoạt các tín hiệu (signals) cho traces, metrics và logs
export OTEL_DOTNET_AUTO_[SIGNALS]_ENABLED="true"

# Cấu hình OTLP exporter cho từng tín hiệu
export OTEL_EXPORTER_OTLP_[SIGNALS]_ENDPOINT="your_signal_endpoint"

# Cấu hình các headers (ví dụ: Token Authentication) cho OTLP exporter
export OTEL_EXPORTER_OTLP_[SIGNALS]_HEADERS="Authorization=<your_token>"

# Chạy ứng dụng
OTEL_SERVICE_NAME=OrderApp OTEL_RESOURCE_ATTRIBUTES=deployment.environment=staging,service.version=1.0.0 ./OrderApp

5. Container

Bước 1: Cập nhật dockerfile

FROM mcr.microsoft.com/dotnet/sdk:8.0.416-jammy@sha256:71217e2029c9844f13aa98114ae4aea9e77287cd8c152f7b7c09f8af61a1affa

# install OpenTelemetry .NET Automatic Instrumentation
ARG OTEL_VERSION=1.13.0
ENV OTEL_DOTNET_AUTO_HOME=/otel-dotnet-auto
ADD https://github.com/open-telemetry/opentelemetry-dotnet-instrumentation/releases/download/v${OTEL_VERSION}/otel-dotnet-auto-install.sh otel-dotnet-auto-install.sh
RUN apt-get update && apt-get install -y unzip && \
    sh otel-dotnet-auto-install.sh
RUN chmod +x /otel-dotnet-auto/instrument.sh

WORKDIR /app
COPY . .
RUN dotnet publish -c Release -o out

Bước 2: Cập nhật biến môi trường

  service:
    build:
      context: .
      dockerfile: Dockerfile
    entrypoint: "/otel-dotnet-auto/instrument.sh dotnet service.dll"
    environment:
    OTEL_SERVICE_NAME: "service"
    OTEL_EXPORTER_OTLP_PROTOCOL: "http/protobuf"
    OTEL_LOGS_EXPORTER: "otlp"
    OTEL_TRACES_EXPORTER: "otlp"
    OTEL_METRICS_EXPORTER: "otlp"
    OTEL_EXPORTER_OTLP_TRACES_ENDPOINT: "https://traces-xxx.apm.vnptplatform.vn/v1/traces"
    OTEL_EXPORTER_OTLP_TRACES_HEADERS: "Authorization=<your_endpoint>"
    OTEL_EXPORTER_OTLP_METRICS_ENDPOINT: "https://metrics-xxx.apm.vnptplatform.vn/otlp/v1/metrics"
    OTEL_EXPORTER_OTLP_METRICS_HEADERS: "Authorization=<your_endpoint>"
    OTEL_EXPORTER_OTLP_LOGS_ENDPOINT: "https://logs-xxx.apm.vnptplatform.vn/otlp/v1/logs"
    OTEL_EXPORTER_OTLP_LOGS_HEADERS: "Authorization=<your_endpoint>"