SinkSharp.Sinks.OpenTelemetry
1.0.1
dotnet add package SinkSharp.Sinks.OpenTelemetry --version 1.0.1
NuGet\Install-Package SinkSharp.Sinks.OpenTelemetry -Version 1.0.1
<PackageReference Include="SinkSharp.Sinks.OpenTelemetry" Version="1.0.1" />
<PackageVersion Include="SinkSharp.Sinks.OpenTelemetry" Version="1.0.1" />
<PackageReference Include="SinkSharp.Sinks.OpenTelemetry" />
paket add SinkSharp.Sinks.OpenTelemetry --version 1.0.1
#r "nuget: SinkSharp.Sinks.OpenTelemetry, 1.0.1"
#:package SinkSharp.Sinks.OpenTelemetry@1.0.1
#addin nuget:?package=SinkSharp.Sinks.OpenTelemetry&version=1.0.1
#tool nuget:?package=SinkSharp.Sinks.OpenTelemetry&version=1.0.1
SinkSharp.Sinks.OpenTelemetry
Send fully-enriched, PII-masked SinkSharp log events to any OpenTelemetry backend via binary Protobuf OTLP — Jaeger, Grafana Loki, Datadog, New Relic, Honeycomb, Azure Monitor, or any self-hosted OTel Collector. One sink, one config object, any backend.
Install
dotnet add package SinkSharp.Core
dotnet add package SinkSharp.Sinks.OpenTelemetry
Quick start — 3 steps
// Step 1: configure OtlpLogSinkOptions (logs + traces share the same endpoint)
var otlpOptions = new OtlpLogSinkOptions
{
Endpoint = new Uri("http://localhost:4317"),
Protocol = OtlpProtocol.Grpc,
ServiceName = "MyApp",
ServiceVersion = "1.0.0",
DeploymentEnvironment = env,
};
// Step 2: SinkSharp pipeline — OtlpLogSink receives events after enrichment and PII masking
builder.Services.AddSinkSharp(options => options
.WithCorrelationId() // CorrelationId → correlation.id on every OTel log record
.WithEnvironment("MyApp", env) // AppName, Environment, MachineName → OTel attributes
.WithPiiMasking() // email, phone, card, SSN masked before OTLP write
.WithUserContext() // UserId, UserName, UserRole → OTel attributes
.WriteTo(new ColoredConsoleSink(), LogLevel.Debug)
.WriteTo(new OtlpLogSink(otlpOptions), LogLevel.Information));
builder.Services.AddSinkSharpDashboard(dashSink);
builder.Services.AddSinkSharpRequestId();
builder.Services.AddSinkSharpRequestPath();
builder.Services.AddSinkSharpElapsedTime();
// Step 3: distributed tracing (optional — independent of OtlpLogSink)
builder.Services.AddSinkSharpTracing(otlpOptions, tracing => tracing
.AddAspNetCoreInstrumentation(o => o.RecordException = true)
.AddHttpClientInstrumentation()
.AddOtlpExporter(o =>
{
o.Endpoint = otlpOptions.Endpoint;
o.Protocol = OpenTelemetry.Exporter.OtlpExportProtocol.Grpc;
}));
Supported backends
The same OtlpLogSinkOptions works with every backend. Switch backends by changing the endpoint and optionally adding an API key header — no other code changes required.
| Backend | Endpoint | Protocol | Header |
|---|---|---|---|
| Jaeger all-in-one | http://jaeger:4318 |
HttpProtobuf | — |
| Grafana Loki (via Collector) | http://otel-collector:4317 |
Grpc | — |
| Datadog Agent | http://datadog-agent:4317 |
Grpc | — |
| Datadog OTLP intake | https://http-intake.logs.datadoghq.com/api/v2/logs |
HttpProtobuf | DD-API-KEY |
| New Relic | https://otlp.nr-data.net:4317 |
Grpc | api-key |
| Honeycomb | https://api.honeycomb.io |
HttpProtobuf | x-honeycomb-team |
| Azure Monitor | via OTel Collector | Grpc | — |
| Any OTel Collector | http://otelcol:4317 or :4318 |
Grpc or HttpProtobuf | — |
OtlpLogSinkOptions
new OtlpLogSinkOptions
{
Endpoint = new Uri("http://localhost:4317"),
Protocol = OtlpProtocol.Grpc, // or OtlpProtocol.HttpProtobuf
ServiceName = "MyApp",
ServiceVersion = "1.0.0",
DeploymentEnvironment = "production",
Headers = new() { ["DD-API-KEY"] = config["Datadog:ApiKey"] },
BatchSize = 512, // flush when batch fills
FlushInterval = TimeSpan.FromSeconds(5), // background timer flush
ExportTimeout = TimeSpan.FromSeconds(10),
RetryCount = 3, // exponential back-off: 1s → 2s → 4s
}
LogEvent → OTel LogRecord mapping
Every SinkSharp LogEvent maps to an OTel LogRecord per the OTel Log Data Model specification.
| SinkSharp field | OTel LogRecord field |
|---|---|
Timestamp |
TimeUnixNano |
Level |
SeverityNumber + SeverityText |
RenderedMessage |
Body |
MessageTemplate |
Attributes["log.record.original"] |
Category |
Attributes["code.namespace"] |
CorrelationId |
Attributes["correlation.id"] |
Properties["AppName"] etc. |
Attributes (all enricher values) |
Exception.GetType() |
Attributes["exception.type"] |
Exception.Message |
Attributes["exception.message"] |
Exception.ToString() |
Attributes["exception.stacktrace"] |
Activity.Current.TraceId |
Attributes["trace.id"] |
Activity.Current.SpanId |
Attributes["span.id"] |
OtlpLogSink vs AddSinkSharpTracing
These two are independent. Use one or both depending on your needs.
OtlpLogSink |
AddSinkSharpTracing |
|
|---|---|---|
| What it sends | Log messages | HTTP request spans |
| Port | 4318 HTTP or 4317 gRPC | 4317 gRPC |
| Loki | ✅ All log lines with structured metadata | — |
| Jaeger trace list | — | ✅ All HTTP request spans |
| Jaeger Logs tab | — | ✅ Span events via Activity.AddEvent() |
| PII masking | ✅ Before OTLP write | ✅ In span event tags |
| Required for Loki | ✅ | ❌ Not needed |
| Required for Jaeger traces | ❌ Not needed | ✅ |
Docker Compose — Grafana + Loki + Jaeger
# Full Grafana stack
docker compose --profile grafana up -d
dotnet run --launch-profile Grafana
# Logs: http://localhost:3000 → Explore → Loki
# Traces: http://localhost:16686
# Jaeger only
docker compose --profile jaeger up -d
dotnet run --launch-profile Jaeger
# Traces: http://localhost:16686
See SinkSharp.OpenTelemetrySample for a complete working sample with all three backends.
Dependencies
| Package | Version | Purpose |
|---|---|---|
SinkSharp.Core |
≥1.0.10 | LogEvent, ISink, enricher pipeline |
OpenTelemetry.Extensions.Hosting |
1.20.1 | AddSinkSharpTracing() registration |
Release notes
v1.0.1
- Fixed binary Protobuf field numbers to match current opentelemetry-proto spec — resolves
wrong wireTypeerrors on all backends - Fixed gRPC HTTP/2 transport for plain
http://endpoints —EnableMultipleHttp2ConnectionsandHttpVersionPolicy.RequestVersionOrHigher - Removed
Google.Protobufdirect dependency — wire format now uses manual varint encoding - Verified working with Grafana Loki 3.4.1, Jaeger 1.65.0, OTel Collector 0.164.0
v1.0.0
OtlpLogSink— ISink that exports to any OTLP backend via binary ProtobufOtlpLogSinkOptions— unified config for endpoint, protocol, headers, service attributes, batching, retryOtlpProtocolenum —Grpc(port 4317) andHttpProtobuf(port 4318)AddSinkSharpTracing()— distributed tracing registration with configureTracing callbackOtlpSuppressingHandler— prevents instrumentation libraries from tracing the sink's own export calls- Binary Protobuf wire format implemented from scratch using Google.Protobuf — no third-party proto package
- Verified working with Grafana Loki, Jaeger, and Datadog
Links
| Website | https://sinksharp.com |
| NuGet | https://www.nuget.org/packages/SinkSharp.Sinks.OpenTelemetry |
| Sample | samples/SinkSharp.OpenTelemetrySample |
| Support | support@sinksharp.com |
| Licence | Apache 2.0 |
| Changelog | CHANGELOG.md |
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net9.0
- OpenTelemetry.Extensions.Hosting (>= 1.20.0)
- SinkSharp.Core (>= 1.0.10)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
v1.0.1 — Wire format fix and gRPC transport improvements
• Fixed OTLP binary Protobuf field numbers to match current opentelemetry-proto spec:
severity_number = field 2, severity_text = field 3 (field 4 is reserved in the proto)
Previously used wrong field numbers which caused "wrong wireType" errors on all backends
• Fixed gRPC transport for plain http:// endpoints (port 4317):
Added EnableMultipleHttp2Connections=true and HttpVersionPolicy.RequestVersionOrHigher
so .NET uses HTTP/2 instead of downgrading to HTTP/1.1 on non-TLS gRPC connections
• Removed Google.Protobuf package dependency — ProtoWriter now uses manual varint
encoding with no external proto library required
• Verified working: Grafana Loki 3.4.1, Jaeger 1.65.0, OTel Collector 0.164.0
v1.0.0 — Initial release
• OtlpLogSink — OTLP log export via binary Protobuf over gRPC (port 4317) or HTTP (port 4318)
• PII masking in-process before OTLP export — CorrelationId, UserId, RequestPath, ElapsedMs on every record
• OtlpProtocol enum — Grpc and HttpProtobuf
• AddSinkSharpTracing() — distributed tracing registration via configureTracing callback
• OtlpSuppressingHandler — prevents instrumentation from tracing the sink's own export calls
• Supported backends: Jaeger, Grafana Loki, Datadog, New Relic, Honeycomb, Azure Monitor
See full changelog: https://github.com/SinkSharp/CHANGELOG.md