opentelemetry-dotnet
opentelemetry-dotnet copied to clipboard
`process.command_args` serializes as `System.String[]`
Bug Report
List of all OpenTelemetry NuGet
packages and version that you are
using (e.g. OpenTelemetry 1.0.2
):
- OpenTelemetry.Exporter.Console: 1.3.0-beta.1
- OpenTelemetry.Exporter.Jaeger: 1.3.0-beta.1
- OpenTelemetry.Exporter.OpenTelemetryProtocol: 1.3.0-beta.1
- OpenTelemetry.Exporter.Prometheus: 1.3.0-beta.1
- OpenTelemetry.Extensions.Hosting: 1.0.0-rc9.3
- OpenTelemetry.Instrumentation.AspNetCore: 1.0.0-rc9.3
- OpenTelemetry.Instrumentation.Http: 1.0.0-rc9.3
Runtime version (e.g. net462
, net48
, netcoreapp3.1
, net6.0
etc. You can
find this information from the *.csproj
file):
- net6.0
Symptom
I'm adding the process.command_args
metadata to a trace resource and when it is serialized to a trace span it appears as System.String[]
instead of the actual array of values. I see this in both the Console exporter as well as using OpenTelemetry Collector.
What is the expected behavior?
I expect the array of arguments to be kept as an array of strings as defined in the spec.
What is the actual behavior?
The value is rendered like .ToString()
was called on the array, so it's System.String[]
instead of the values.
Reproduce
Create a resource detector like this:
using System.Runtime.InteropServices;
using OpenTelemetry.Resources;
namespace MyNamespace;
public class RuntimeResourceDetector : IResourceDetector
{
public Resource Detect()
{
var process = Process.GetCurrentProcess();
var filename = process.MainModule.FileName;
// Command line args requires the executable per OpenTelemetry spec.
var arguments = Environment.GetCommandLineArgs().Prepend(filename).ToArray();
var resourceData = new Dictionary<string, object>()
{
{ OpenTelemetrySemanticResourceKey.ProcessCommandArgs, arguments }
};
return new Resource(resourceData);
}
}
Add that to your resource when you wire up trace.
var resourceBuilder = ResourceBuilder
.CreateEmpty()
.Add(new RuntimeResourceDetector());
services.AddOpenTelemetryTracing(builder =>
builder
.SetResourceBuilder(resourceBuilder)
.AddConsoleExporter());
Detection runs totally fine, and if you debug it, you can see that the proper array of arguments is getting added to the resource. However, when it serializes, you'll see...
Resource associated with Activity:
process.command_args: System.String[]
Additional Context
I noticed a similar issue about array serialization but it was for span attributes, not resource attributes. I think this is happening in this ToOtlpAttribute()
method, at least for the OpenTelemetry exporter, but I haven't really figured out how it's happening for the console exporter yet. Admittedly I haven't super dug in; I just noticed it and was puzzled.
Digging up an old, but I think related to this https://github.com/open-telemetry/opentelemetry-dotnet/pull/1973
Based on some discussion in #3238 it seems like there is some work in #2010 that is going on that will affect this. Since I'm not on the inside track with what's going on there, I don't know that I'll personally be able to do a PR to fix this issue. However, if someone can give me some tips/guidance on what to do (or what I should be waiting for), I'd be happy to chip in.
Hmm, this is probably not completely resolved yet, so reopening... I think the Console exporter requires a little work - should be easy, I'll take a look. Will look at Prometheus too.