/

OpenTelemetry Overview

ByteHide Logger supports OpenTelemetry integration, allowing you to export logs alongside traces and metrics in a standardized format. This enables comprehensive observability across your distributed applications.

What is OpenTelemetry?

OpenTelemetry (OTEL) is an open-source observability framework that provides:

  • Unified Standards: Common APIs and data formats for logs, traces, and metrics
  • Vendor Neutrality: Export data to any compatible backend
  • Distributed Tracing: Track requests across multiple services
  • Correlation: Link logs, traces, and metrics together

ByteHide Logger Integration

ByteHide Logger seamlessly integrates with OpenTelemetry by:

Automatic Trace Correlation

// When using OpenTelemetry tracing, ByteHide logs automatically include:
// - Trace ID
// - Span ID  
// - Activity context

using var activity = ActivitySource.StartActivity("ProcessOrder");

Log.WithCorrelationId("order-123")
   .Info("Processing order"); // Automatically includes trace context

Standard Log Format

ByteHide Logger exports logs in OpenTelemetry format with:

  • Timestamp: ISO 8601 format
  • Severity: Mapped to OpenTelemetry levels
  • Body: Log message and context
  • Attributes: Metadata and custom properties
  • Resource: Application and service information

Correlation IDs as Trace IDs

// Correlation IDs work seamlessly with OpenTelemetry traces
var traceId = Activity.Current?.TraceId.ToString();

Log.WithCorrelationId(traceId)
   .Error("Payment failed", exception);

Benefits of Integration

Distributed Observability

// Service A
Log.WithCorrelationId("req-123")
   .WithTags("service-a", "api")
   .Info("Received user request");

// Service B (same correlation ID)
Log.WithCorrelationId("req-123")
   .WithTags("service-b", "database")
   .Error("Database connection failed", ex);

Unified Dashboards

Export ByteHide logs to observability platforms:

  • Jaeger: For distributed tracing
  • Prometheus: For metrics correlation
  • Grafana: For unified dashboards
  • Elastic Stack: For log analysis
  • Azure Monitor: For cloud observability

Performance Monitoring

using var activity = ActivitySource.StartActivity("DatabaseQuery");

var stopwatch = Stopwatch.StartNew();
try
{
    var result = await database.QueryAsync(sql);
    
    Log.WithMetadata("duration", stopwatch.ElapsedMilliseconds)
       .WithMetadata("rows", result.Count)
       .Info("Database query completed");
}
catch (Exception ex)
{
    Log.WithMetadata("duration", stopwatch.ElapsedMilliseconds)
       .Error("Database query failed", ex);
}

Common Use Cases

Microservices Architecture

// Gateway Service
Log.WithCorrelationId(context.TraceIdentifier)
   .WithTags("gateway", "routing")
   .Info("Routing request to user service");

// User Service
Log.WithCorrelationId(context.TraceIdentifier)
   .WithTags("user-service", "authentication")
   .Info("Authenticating user");

// Database Service
Log.WithCorrelationId(context.TraceIdentifier)
   .WithTags("database", "query")
   .Error("Connection timeout", ex);

Error Tracking

try
{
    await ProcessPaymentAsync(payment);
}
catch (PaymentException ex)
{
    // Error automatically correlated with trace
    Log.WithMetadata("paymentId", payment.Id)
       .WithMetadata("amount", payment.Amount)
       .Error("Payment processing failed", ex);
    
    // OpenTelemetry will correlate this error with the trace
    throw;
}

Performance Analysis

using var activity = ActivitySource.StartActivity("ProcessOrder");

Log.WithTags("performance", "order-processing")
   .Info("Starting order processing");

// Processing logic...

Log.WithTags("performance", "order-processing")
   .WithMetadata("processingTime", stopwatch.ElapsedMilliseconds)
   .Info("Order processing completed");

Integration Requirements

.NET Requirements

  • .NET 6+: Native OpenTelemetry support
  • .NET Standard 2.0+: Compatible with System.Diagnostics.Activity
  • ASP.NET Core: Built-in tracing support

Package Dependencies

ByteHide Logger works with standard OpenTelemetry packages:

<PackageReference Include="OpenTelemetry" Version="1.6.0" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.6.0" />
<PackageReference Include="OpenTelemetry.Exporter.Jaeger" Version="1.5.1" />

Next Steps

Previous
MAUI