opentelemetry-dotnet-contrib icon indicating copy to clipboard operation
opentelemetry-dotnet-contrib copied to clipboard

Null attributes not handled properly

Open SebastianStehle opened this issue 1 year ago • 0 comments

Issue with OpenTelemetry.Exporter.Stackdriver

Stackdriver Beta1 (Open Telemetry Versions are not relevant)

Is this a feature request or a bug?

  • [ ] Feature Request
  • [x] Bug

I just the following exception:

Value cannot be null. (Parameter 'value') | System.ArgumentNullException
   at Google.Protobuf.ProtoPreconditions.CheckNotNullUnconstrained[T](T value, String name)
   at Google.Protobuf.Collections.MapField`2.set_Item(TKey key, TValue value)
   at Google.Protobuf.Collections.MapField`2.Add(TKey key, TValue value)
   at Google.Protobuf.Collections.MapField`2.Add(IDictionary`2 entries)
   at OpenTelemetry.Contrib.Exporter.Stackdriver.Implementation.ActivityExtensions.ToSpan(Activity activity, String projectId)
   at OpenTelemetry.Contrib.Exporter.Stackdriver.StackdriverTraceExporter.Export(Batch`1& batchActivity)
   at OpenTelemetry.BatchExportProcessor`1.ExporterProc()
   at System.Threading.Thread.StartCallback()

I think it is related to this line:

https://github.com/open-telemetry/opentelemetry-dotnet-contrib/blob/main/src/OpenTelemetry.Exporter.Stackdriver/Implementation/ActivityExtensions.cs#L88

It makes totally sense, because AttributeMap is a GRPC structure, and GRPC does not accept null in general.

I reproduced it with the following example:

// See https://aka.ms/new-console-template for more information
using Google.Cloud.Trace.V2;
using OpenTelemetry.Exporter.Stackdriver;
using System.Diagnostics;

var toSpan = 
    typeof(StackdriverTraceExporter).Assembly
        .GetType("OpenTelemetry.Exporter.Stackdriver.Implementation.ActivityExtensions")!
        .GetMethod("ToSpan")!
        .CreateDelegate<Func<Activity, string, Span>>();

var activity = new Activity("Operation");
activity.AddTag("Key", null);
activity.Start();
activity.Stop();

var x = toSpan(activity, "PROJECT-ID");

SebastianStehle avatar Aug 08 '22 07:08 SebastianStehle