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

Fix null tags. #566

Merged
merged 10 commits into from
Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,15 @@ public static Span.Types.Link ToLink(this ActivityLink link)
{
link.Tags.ToDictionary(
att => att.Key,
att => att.Value.ToAttributeValue()),
att => att.Value?.ToAttributeValue()),
},
};
}

return ret;
}

public static AttributeValue ToAttributeValue(this object av)
public static AttributeValue ToAttributeValue(this object? av)
{
switch (av)
{
Expand All @@ -146,6 +146,8 @@ public static AttributeValue ToAttributeValue(this object av)
{
StringValue = new TruncatableString() { Value = d.ToString() },
};
case null:
return new AttributeValue();
default:
return new AttributeValue()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ public override ExportResult Export(in Batch<Activity> batchActivity)

foreach (var activity in batchActivity)
{
batchSpansRequest.Spans.Add(activity.ToSpan(this.googleCloudProjectId.ProjectId));
// It should never happen that the time has no correct kind, only if OpenTelemetry is used incorrectly.
if (activity.StartTimeUtc.Kind == DateTimeKind.Utc)
{
batchSpansRequest.Spans.Add(activity.ToSpan(this.googleCloudProjectId.ProjectId));
}
}

// avoid cancelling here: this is no return point: if we reached this point
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Description>Unit test project for Stackdriver Exporter for OpenTelemetry</Description>
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void StackdriverExporter_TraceClientThrows_ExportResultFailure()

for (int i = 0; i < 10; i++)
{
using Activity activity = source.StartActivity("Test Activity");
using Activity activity = CreateTestActivity();
processor.OnEnd(activity);
}

Expand Down Expand Up @@ -147,7 +147,7 @@ public void StackdriverExporter_TraceClientDoesNotTrow_ExportResultSuccess()

for (int i = 0; i < 10; i++)
{
using Activity activity = source.StartActivity("Test Activity");
using Activity activity = CreateTestActivity();
processor.OnEnd(activity);
}

Expand Down Expand Up @@ -192,6 +192,7 @@ internal static Activity CreateTestActivity(
{ "doubleKey", 1D },
{ "doubleKey2", 1F },
{ "boolKey", true },
{ "nullKey", null },
};
if (additionalAttributes != null)
{
Expand Down Expand Up @@ -224,7 +225,7 @@ internal static Activity CreateTestActivity(
var activitySource = new ActivitySource(nameof(CreateTestActivity));

var tags = setAttributes ?
attributes.Select(kvp => new KeyValuePair<string, object>(kvp.Key, kvp.Value.ToString()))
attributes.Where(x => x.Value != null).Select(kvp => new KeyValuePair<string, object>(kvp.Key, kvp.Value.ToString()))
: null;
var links = addLinks ?
new[]
Expand Down