Search code examples
c#.netserilogopen-telemetryserilog-sinks-opentelemetry

Serilog OpenTelemetrySink Objects shown as kvlistValue in Aspire Dashboard


When I log structured objects using the OpenTelemetry package for .NET, complex objects appear in Aspire dashboard as JSON strings.

When I log complex objects with Serilog OpenTelemetrySink, I see something like

enter image description here

I understand that OpenTelemetry specifies that complex objects are sent in this format, but the collector should be decoding that back into an object or at least a JSON string.

I am trying to figure out if this is a misconfiguration on my part, or if it is a bug in the OpenTelemetrySink

My serilog configuration

services.AddLogging(
            loggingBuilder =>
            {
                //Create Serilog logger from AppSettings.json properties.
                LoggerConfiguration loggingConfiguration = new LoggerConfiguration()
                    .ReadFrom.Configuration(configuration);

                string? otelExporterEndpoint = Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"];
                if (otelExporterEndpoint != null)
                {
                    loggingConfiguration.WriteTo.OpenTelemetry(
                        opt =>
                        {
                            opt.Endpoint = otelExporterEndpoint;
                            opt.Protocol = OtlpProtocol.Grpc;
                            opt.ResourceAttributes = _otelResourceAttributes;
                            opt.OnBeginSuppressInstrumentation =
                                SuppressInstrumentationScope.Begin;
                            opt.IncludedData = IncludedData.TemplateBody | IncludedData.SpanIdField |
                                               IncludedData.TraceIdField | IncludedData.SourceContextAttribute;
                        });
                }

                _logger = loggingConfiguration.CreateLogger();
                loggingBuilder.AddSerilog(_logger, dispose: true);

                // Enable selflog to debug serilog configuration
                // SelfLog.Enable(Console.Error);
            });

Solution

  • You're running version 8.1 or earlier of the Aspire Dashboard. If you pull 8.2 or later (currently mcr.microsoft.com/dotnet/nightly/aspire-dashboard:8.2), incoming structured data will be properly rendered.