Skip to content

Commit

Permalink
fix span kind
Browse files Browse the repository at this point in the history
  • Loading branch information
eventhorizon-cli committed Jan 20, 2024
1 parent c23116a commit a6f079e
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/Mocha.Core/Models/Trace/MochaSpanKind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ namespace Mocha.Core.Models.Trace;
public enum MochaSpanKind
{
Unspecified = 0,
Client = 1,
Internal = 1,
Server = 2,
Internal = 3,
Client = 3,
Producer = 4,
Consumer = 5
}
14 changes: 14 additions & 0 deletions src/Mocha.Core/Storage/Jaeger/Trace/JaegerSpanKind.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Licensed to the .NET Core Community under one or more agreements.
// The .NET Core Community licenses this file to you under the MIT license.

namespace Mocha.Core.Storage.Jaeger.Trace;

public static class JaegerSpanKind
{
public const string Unspecified = "unspecified";
public const string Internal = "internal";
public const string Server = "server";
public const string Client = "client";
public const string Producer = "producer";
public const string Consumer = "consumer";
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,10 @@ public static IEnumerable<JaegerTrace> ToJaegerTraces(
.GroupBy(s => s.TraceID)
.Select(g =>
{
var spans = g.ToArray();
var spansOfCurrentTrace = g.ToArray();
var jaegerProcesses = new List<JaegerProcess>();
foreach (var span in spans)
foreach (var span in spansOfCurrentTrace)
{
resourceAttributesBySpanId.TryGetValue(span.SpanID, out var attributes);
attributes ??= Array.Empty<EFResourceAttribute>();
Expand All @@ -80,7 +79,7 @@ public static IEnumerable<JaegerTrace> ToJaegerTraces(
Processes = jaegerProcesses
.DistinctBy(p => p.ProcessID)
.ToDictionary(p => p.ProcessID),
Spans = spans
Spans = spansOfCurrentTrace
};
});

Expand Down Expand Up @@ -115,7 +114,7 @@ private static IEnumerable<JaegerSpan> ToJaegerSpans(
RefType = JaegerSpanReferenceType.ChildOf,
}
],
Tags = spanAttributes.Select(ToJaegerTag).ToArray(),
Tags = spanAttributes.ToJaegerSpanTags(span).ToArray(),
Logs = spanEvents.ToJaegerSpanLogs(spanEventAttributes).ToArray()
};

Expand All @@ -135,6 +134,28 @@ private static JaegerTag ToJaegerTag(this AbstractEFAttribute attribute)
return jaegerTag;
}

private static IEnumerable<JaegerTag> ToJaegerSpanTags(
this IEnumerable<EFSpanAttribute> spanAttributes,
EFSpan span)
{
if (span.StatusCode == EFSpanStatusCode.Error)
{
yield return new JaegerTag { Key = "error", Type = JaegerTagType.Bool, Value = true };
}

yield return new JaegerTag
{
Key = "span.kind",
Type = JaegerTagType.String,
Value = span.SpanKind.ToJaegerSpanKind()
};

foreach (var attribute in spanAttributes)
{
yield return attribute.ToJaegerTag();
}
}

private static IEnumerable<JaegerSpanLog> ToJaegerSpanLogs(
this IEnumerable<EFSpanEvent> spanEvents,
IEnumerable<EFSpanEventAttribute> spanEventAttributes)
Expand Down Expand Up @@ -175,6 +196,16 @@ private static IEnumerable<JaegerSpanLog> ToJaegerSpanLogs(
_ => throw new ArgumentOutOfRangeException()

Check warning on line 196 in src/Mocha.Storage/EntityFrameworkCore/Jaeger/EFToJaegerSpanConversionExtensions.cs

View check run for this annotation

Codecov / codecov/patch

src/Mocha.Storage/EntityFrameworkCore/Jaeger/EFToJaegerSpanConversionExtensions.cs#L193-L196

Added lines #L193 - L196 were not covered by tests
};

private static string ToJaegerSpanKind(this EFSpanKind spanKind) => spanKind switch

Check warning on line 199 in src/Mocha.Storage/EntityFrameworkCore/Jaeger/EFToJaegerSpanConversionExtensions.cs

View workflow job for this annotation

GitHub Actions / dotnet-build

The switch expression does not handle some values of its input type (it is not exhaustive) involving an unnamed enum value. For example, the pattern '(Mocha.Storage.EntityFrameworkCore.Trace.EFSpanKind)6' is not covered.

Check warning on line 199 in src/Mocha.Storage/EntityFrameworkCore/Jaeger/EFToJaegerSpanConversionExtensions.cs

View workflow job for this annotation

GitHub Actions / dotnet-build

The switch expression does not handle some values of its input type (it is not exhaustive) involving an unnamed enum value. For example, the pattern '(Mocha.Storage.EntityFrameworkCore.Trace.EFSpanKind)6' is not covered.

Check warning on line 199 in src/Mocha.Storage/EntityFrameworkCore/Jaeger/EFToJaegerSpanConversionExtensions.cs

View workflow job for this annotation

GitHub Actions / dotnet-build

The switch expression does not handle some values of its input type (it is not exhaustive) involving an unnamed enum value. For example, the pattern '(Mocha.Storage.EntityFrameworkCore.Trace.EFSpanKind)6' is not covered.
{
EFSpanKind.Unspecified => JaegerSpanKind.Unspecified,
EFSpanKind.Internal => JaegerSpanKind.Internal,

Check warning on line 202 in src/Mocha.Storage/EntityFrameworkCore/Jaeger/EFToJaegerSpanConversionExtensions.cs

View check run for this annotation

Codecov / codecov/patch

src/Mocha.Storage/EntityFrameworkCore/Jaeger/EFToJaegerSpanConversionExtensions.cs#L201-L202

Added lines #L201 - L202 were not covered by tests
EFSpanKind.Server => JaegerSpanKind.Server,
EFSpanKind.Client => JaegerSpanKind.Client,
EFSpanKind.Producer => JaegerSpanKind.Producer,
EFSpanKind.Consumer => JaegerSpanKind.Consumer,

Check warning on line 206 in src/Mocha.Storage/EntityFrameworkCore/Jaeger/EFToJaegerSpanConversionExtensions.cs

View check run for this annotation

Codecov / codecov/patch

src/Mocha.Storage/EntityFrameworkCore/Jaeger/EFToJaegerSpanConversionExtensions.cs#L205-L206

Added lines #L205 - L206 were not covered by tests
};

private static object ConvertTagValue(this EFAttributeValueType valueType, string value) => valueType switch
{
EFAttributeValueType.StringValue => value,
Expand Down
4 changes: 2 additions & 2 deletions src/Mocha.Storage/EntityFrameworkCore/Trace/EFSpanKind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ namespace Mocha.Storage.EntityFrameworkCore.Trace;
public enum EFSpanKind
{
Unspecified = 0,
Client = 1,
Internal = 1,
Server = 2,
Internal = 3,
Client = 3,
Producer = 4,
Consumer = 5
}

0 comments on commit a6f079e

Please sign in to comment.