Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

process.command_args serializes as System.String[] #3229

Closed
tillig opened this issue Apr 22, 2022 · 5 comments · Fixed by #3281
Closed

process.command_args serializes as System.String[] #3229

tillig opened this issue Apr 22, 2022 · 5 comments · Fixed by #3281
Labels
bug Something isn't working Stale Issues and pull requests which have been flagged for closing due to inactivity

Comments

@tillig
Copy link
Contributor

tillig commented Apr 22, 2022

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.

@tillig tillig added the bug Something isn't working label Apr 22, 2022
@cijothomas
Copy link
Member

Digging up an old, but I think related to this #1973

@tillig
Copy link
Contributor Author

tillig commented May 5, 2022

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.

@alanwest
Copy link
Member

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.

Copy link
Contributor

This issue was marked stale due to lack of activity and will be closed in 7 days. Commenting will instruct the bot to automatically remove the label. This bot runs once per day.

@github-actions github-actions bot added the Stale Issues and pull requests which have been flagged for closing due to inactivity label Sep 25, 2024
Copy link
Contributor

github-actions bot commented Oct 3, 2024

Closed as inactive. Feel free to reopen if this issue is still a concern.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Stale Issues and pull requests which have been flagged for closing due to inactivity
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants