NetKit.OpenTelemetry 1.0.1

dotnet add package NetKit.OpenTelemetry --version 1.0.1                
NuGet\Install-Package NetKit.OpenTelemetry -Version 1.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NetKit.OpenTelemetry" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NetKit.OpenTelemetry --version 1.0.1                
#r "nuget: NetKit.OpenTelemetry, 1.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install NetKit.OpenTelemetry as a Cake Addin
#addin nuget:?package=NetKit.OpenTelemetry&version=1.0.1

// Install NetKit.OpenTelemetry as a Cake Tool
#tool nuget:?package=NetKit.OpenTelemetry&version=1.0.1                

Installation

  1. Install NetKit.OpenTelemetry package:
PM> Install-Package NetKit.OpenTelemetry
  1. Add these configuration below in your project:

appsettingsSettings.json

{
    "OpenTelemetry": {
        "UseTracingExporter": "otlp",
        "UseMetricsExporter": "otlp",
        "UseLogExporter": "otlp",
        "Jaeger": {
            "ServiceName": "jaeger-test",
            "AgentHost": "localhost",
            "AgentPort": 6831,
            "Endpoint": "http://localhost:14268",
            "Protocol": "UdpCompactThrift"
        },
        "Prometheus": {
            "ScrapeResponseCacheDurationMilliseconds": 5000
        },
        "Zipkin": {
            "ServiceName": "zipkin-test",
            "Endpoint": "http://localhost:9411/api/v2/spans"
        },
        "Otlp": {
            "ServiceName": "otlp-test",
            "Endpoint": "http://localhost:4317"
        },
        "AspNetCoreInstrumentation": {
            "RecordException": "true"
        }
    }
}

collector-config.yml

# Configure receivers
# We only need otlp protocol on grpc, but you can use http, zipkin, jaeger, aws, etc.
# https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver
receivers:
  otlp:
    protocols:
      grpc:

# Configure exporters
exporters:
  # Export prometheus endpoint
  prometheus:
    endpoint: "0.0.0.0:8889"

  # log to the console
  logging:

  # Export to zipkin
  zipkin:
    endpoint: "http://zipkin-all-in-one:9411/api/v2/spans"
    format: proto

  # Export to a file
  file:
    path: /etc/output/logs.json

# Configure processors (batch, sampling, filtering, hashing sensitive data, etc.)
# https://opentelemetry.io/docs/collector/configuration/#processors
processors:
  batch:

# Configure pipelines. Pipeline defines a path the data follows in the Collector
# starting from reception, then further processing or modification and finally
# exiting the Collector via exporters.
# https://opentelemetry.io/docs/collector/configuration/#service
# https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/design.md#pipelines
service:
  pipelines:
    traces:
      receivers: [otlp]
      processors: [batch]
      exporters: [logging, zipkin]
    metrics:
      receivers: [otlp]
      processors: [batch]
      exporters: [logging, prometheus]
    logs:
      receivers: [otlp]
      processors: []
      exporters: [logging, file]

prometheus.yaml

scrape_configs:
- job_name: 'otel-collector'
  scrape_interval: 10s
  static_configs:
  - targets: ['otel-collector:8889']
  - targets: ['otel-collector:8888']

docker-compose.yml

version: '3.8'

services:
  # back-ends
  zipkin-all-in-one:
    image: openzipkin/zipkin:latest
    ports:
      - "9411:9411"

  prometheus:
    container_name: prometheus
    image: prom/prometheus:latest
    volumes:
      - ./prometheus.yaml:/etc/prometheus/prometheus.yml
    ports:
      - "9090:9090"

  # OpenTelemetry Collector
  otel-collector:
    image: otel/opentelemetry-collector:latest
    command: ["--config=/etc/otel-collector-config.yaml"]
    volumes:
      - ./collector-config.yaml:/etc/otel-collector-config.yaml
      - ./output:/etc/output:rw # Store the logs
    ports:
      - "8888:8888"   # Prometheus metrics exposed by the collector
      - "8889:8889"   # Prometheus exporter metrics
      - "4317:4317"   # OTLP gRPC receiver
    depends_on:
      - zipkin-all-in-one

  1. In Programs.cs, add these line to configure OpenTelemetry in your project:
  • Resolve OpenTelemetry
var openTelemetryInfo = OpenTelemetryExtensions.GetResourceBuilder(builder.Configuration, "AspNetCoreExampleService");
  • Register OpenTelemetry Tracing
builder.Services.AddNetKitOpenTelemetryTracing(builder.Configuration, openTelemetryInfo);

  • Register OpenTelemetry Logging
builder.Services.AddNetKitOpenTelemetryLogging(builder.Configuration, openTelemetryInfo);
  • Register OpenTelemetry Metrics
builder.Services.AddNetKitOpenTelemetryMetrics(builder.Configuration, openTelemetryInfo);
  • If you're using Prometheus exporter, you should adds OpenTelemetry Prometheus scraping endpoint middleware
app.UseNetKitOpenTelemetryMetricsExporter(builder.Configuration);
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.1 241 3/28/2022
1.0.0 212 3/28/2022

Update package info