📡

OtelCollector

A PowerShell module for sending OpenTelemetry traces and metrics — bring observability to your PowerShell scripts and automation pipelines.

⬇️ 5,000+ Downloads
🏷️ v0.1.3 Version
📜 MIT License
Install: Install-Module -Name OtelCollector
⬇️ PowerShell Gallery View on GitHub

Documentation

Overview

OtelCollector (PSOtelCollector) is a PowerShell module that enables sending OpenTelemetry telemetry data — traces, spans, and metrics — directly from PowerShell scripts to any OpenTelemetry-compatible backend (Jaeger, Zipkin, Grafana Tempo, Azure Monitor, etc.).

Bring modern observability practices to your PowerShell automation, runbooks, and CI/CD pipelines.


Installation

Install from the PowerShell Gallery:

# Install for current user
Install-Module -Name OtelCollector -Scope CurrentUser

# Import
Import-Module OtelCollector

Note: Requires PowerShell 7.0 or later.


Quick Start

Initialize the Tracer

Import-Module OtelCollector

# Configure the OTLP exporter endpoint
Initialize-OtelTracer -ServiceName "MyAutomation" -Endpoint "http://localhost:4317"

Create a Trace and Spans

# Start a root span
$span = Start-OtelSpan -Name "deploy-application"

try {
    # Add attributes to the span
    Set-OtelSpanAttribute -Span $span -Key "deployment.environment" -Value "production"
    Set-OtelSpanAttribute -Span $span -Key "app.version" -Value "2.5.0"

    # Child span for a sub-operation
    $childSpan = Start-OtelSpan -Name "run-migration" -ParentSpan $span
    try {
        # ... perform database migration ...
        Invoke-SqlMigration -Server "prod-db" -Database "AppDB"
    } finally {
        Stop-OtelSpan -Span $childSpan
    }

    Write-Host "Deployment complete"
} catch {
    Set-OtelSpanStatus -Span $span -Status "Error" -Description $_.Exception.Message
    throw
} finally {
    Stop-OtelSpan -Span $span
}

Commands

Initialization

CommandDescription
Initialize-OtelTracerConfigure and initialize the OpenTelemetry tracer

Tracing

CommandDescription
Start-OtelSpanBegin a new span
Stop-OtelSpanEnd a span and export it
Set-OtelSpanAttributeAdd a key-value attribute to a span
Set-OtelSpanStatusSet the status of a span (Ok / Error)
Add-OtelSpanEventAdd a timed event to a span

Configuration

Initialize-OtelTracer Parameters

ParameterTypeDefaultDescription
-ServiceNamestring"PowerShell"Name of the service reported in traces
-Endpointstring"http://localhost:4317"OTLP gRPC endpoint URL
-ServiceVersionstring"1.0.0"Service version attribute
-Headershashtable@{}Additional headers (e.g., auth tokens)

Examples

Trace a CI/CD Pipeline

Import-Module OtelCollector

Initialize-OtelTracer -ServiceName "CI-Pipeline" -Endpoint "http://otel-collector:4317"

$pipeline = Start-OtelSpan -Name "ci-pipeline"
Set-OtelSpanAttribute -Span $pipeline -Key "git.branch" -Value "main"
Set-OtelSpanAttribute -Span $pipeline -Key "git.commit" -Value $env:GIT_SHA

# Run tests
$testSpan = Start-OtelSpan -Name "run-tests" -ParentSpan $pipeline
# ... run tests ...
Stop-OtelSpan -Span $testSpan

# Build artifact
$buildSpan = Start-OtelSpan -Name "build" -ParentSpan $pipeline
# ... build ...
Stop-OtelSpan -Span $buildSpan

Stop-OtelSpan -Span $pipeline

Send Metrics

# Record a counter metric
Add-OtelMetric -Name "jobs.processed" -Value 1 -Type Counter `
               -Attributes @{ queue = "email"; status = "success" }

# Record a gauge
Add-OtelMetric -Name "queue.depth" -Value 42 -Type Gauge `
               -Attributes @{ queue = "email" }

Backend Integrations

OtelCollector is compatible with any OTLP-supporting backend:


Contributing

See the GitHub repository for contribution guidelines.


License

OtelCollector is released under the MIT License.

Related Blog Posts