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

Exporting tags consistently #3281

Merged
merged 36 commits into from
May 27, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
3d44019
WIP generalize transforming tags
alanwest May 13, 2022
5c17ba1
Merge branch 'main' into alanwest/tag-transformer
alanwest May 16, 2022
6653468
Make abstract methods protected
alanwest May 17, 2022
bd59744
Add ZipkinTagTransformer
alanwest May 17, 2022
84a1ee7
Simplify ZipkinTagTransformer
alanwest May 17, 2022
9cbb855
Refactor OTLP array attribute transform
alanwest May 18, 2022
fc5bf81
Merge branch 'main' into alanwest/tag-transformer
alanwest May 19, 2022
0c92519
Merge branch 'main' into alanwest/tag-transformer
alanwest May 20, 2022
493ed24
Unused using
alanwest May 20, 2022
0ad99fe
Change Zipkin test. Array values are now represented as JSON arrays.
alanwest May 20, 2022
e8a52a4
net462 and netcoreapp3.1 runtimes are confused about pointer types
alanwest May 20, 2022
643742e
Handle array values better
alanwest May 24, 2022
347ab44
Fix namespace
alanwest May 24, 2022
181e2fa
Handle exceptions when transforming array values
alanwest May 24, 2022
a2c2d69
Log when transform fails
alanwest May 24, 2022
9d9c5d0
Merge branch 'main' into alanwest/tag-transformer
alanwest May 24, 2022
38d17a7
TransformTag -> TryTransformTag
alanwest May 25, 2022
1f09f2c
CodeAnalysis recommendations
alanwest May 25, 2022
bdd17b2
Change OTLP exporter to use TryTransformTag
alanwest May 25, 2022
f3ee3e7
CodeAnalysis
alanwest May 25, 2022
c3dd4ec
CodeAnalysis
alanwest May 25, 2022
76a2f3c
Change Jaeger exporter to use TryTransformTag
alanwest May 25, 2022
38fb5f0
Make TagTransformers singletons
alanwest May 25, 2022
4b7727c
Merge branch 'main' into alanwest/tag-transformer
alanwest May 25, 2022
efc21a4
Unused using
alanwest May 25, 2022
a536bf0
else if
alanwest May 25, 2022
b6cab43
Make singleton Instance a property
alanwest May 25, 2022
5b23656
:seal: classes
alanwest May 25, 2022
040762c
Debug.Assert
alanwest May 25, 2022
fd9f373
Do later
alanwest May 25, 2022
0d31699
Make TransformValue protected
alanwest May 25, 2022
673ade0
Exclude TagTransformer.cs from compilation of SDK project
alanwest May 25, 2022
74df0df
Move JSON serialization to projects that need it
alanwest May 25, 2022
d882145
File-scoped namespaces
alanwest May 25, 2022
4f89b27
Merge branch 'main' into alanwest/tag-transformer
cijothomas May 26, 2022
5fa4281
Update changelogs
alanwest May 26, 2022
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
Prev Previous commit
Next Next commit
Add ZipkinTagTransformer
  • Loading branch information
alanwest committed May 17, 2022
commit bd597449633dc313e61d7e55cc42b18cd934336a
27 changes: 3 additions & 24 deletions src/OpenTelemetry.Exporter.Zipkin/Implementation/ZipkinSpan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void Return()
this.Tags.Return();
}

public void Write(Utf8JsonWriter writer)
public void Write(Utf8JsonWriter writer, ZipkinTagTransformer tagTransformer)
{
writer.WriteStartObject();

Expand Down Expand Up @@ -178,12 +178,12 @@ public void Write(Utf8JsonWriter writer)
{
foreach (var tag in this.LocalEndpoint.Tags ?? Enumerable.Empty<KeyValuePair<string, object>>())
{
writer.WriteString(tag.Key, ConvertObjectToString(tag.Value));
tagTransformer.TransformTag(tag);
}

foreach (var tag in this.Tags)
{
writer.WriteString(tag.Key, ConvertObjectToString(tag.Value));
tagTransformer.TransformTag(tag);
}
}
finally
Expand All @@ -196,26 +196,5 @@ public void Write(Utf8JsonWriter writer)

writer.WriteEndObject();
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static string ConvertObjectToString(object obj)
{
return obj switch
{
string stringVal => stringVal,
bool boolVal => GetBoolString(boolVal),
int[] arrayValue => string.Join(",", arrayValue),
long[] arrayValue => string.Join(",", arrayValue),
double[] arrayValue => string.Join(",", arrayValue),
bool[] arrayValue => string.Join(",", arrayValue.Select(GetBoolString)),
_ => obj.ToString(),
};
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static string GetBoolString(bool value)
{
return value ? "true" : "false";
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// <copyright file="ZipkinTagTransformer.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>

using System.Text.Json;
using OpenTelemetry.Internal;

namespace OpenTelemetry.Exporter.Zipkin.Implementation
{
internal class ZipkinTagTransformer : TagTransformer<bool>
{
private readonly Utf8JsonWriter writer;

public ZipkinTagTransformer(Utf8JsonWriter writer)
{
this.writer = writer;
}

protected override bool JsonifyArrays => true;

protected override bool TransformIntegralTag(string key, long value)
{
this.writer.WriteString(key, value.ToString());
return true;
}

protected override bool TransformFloatingPointTag(string key, double value)
{
this.writer.WriteString(key, value.ToString());
return true;
}

protected override bool TransformBooleanTag(string key, bool value)
{
this.writer.WriteString(key, value ? "true" : "false");
return true;
}

protected override bool TransformStringTag(string key, string value)
{
this.writer.WriteString(key, value.ToString());
return true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<Compile Include="$(RepoRoot)\src\OpenTelemetry\Internal\PeerServiceResolver.cs" Link="Includes\PeerServiceResolver.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry\Internal\ResourceSemanticConventions.cs" Link="Includes\ResourceSemanticConventions.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry\Internal\ServiceProviderExtensions.cs" Link="Includes\ServiceProviderExtensions.cs" />
<Compile Include="$(RepoRoot)\src\OpenTelemetry\Internal\TagTransformer.cs" Link="Includes\TagTransformer.cs" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 3 additions & 1 deletion src/OpenTelemetry.Exporter.Zipkin/ZipkinExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ private sealed class JsonContent : HttpContent
private readonly ZipkinExporter exporter;
private readonly Batch<Activity> batch;
private Utf8JsonWriter writer;
private ZipkinTagTransformer tagTransformer;

public JsonContent(ZipkinExporter exporter, in Batch<Activity> batch)
{
Expand Down Expand Up @@ -232,6 +233,7 @@ private void SerializeToStreamInternal(Stream stream)
if (this.writer == null)
{
this.writer = new Utf8JsonWriter(stream);
this.tagTransformer = new ZipkinTagTransformer(this.writer);
}
else
{
Expand All @@ -244,7 +246,7 @@ private void SerializeToStreamInternal(Stream stream)
{
var zipkinSpan = activity.ToZipkinSpan(this.exporter.LocalEndpoint, this.exporter.options.UseShortTraceIds);

zipkinSpan.Write(this.writer);
zipkinSpan.Write(this.writer, this.tagTransformer);

zipkinSpan.Return();
if (this.writer.BytesPending >= this.exporter.maxPayloadSizeInBytes)
Expand Down