Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelldi committed Jan 17, 2024
1 parent bd74861 commit 378d1aa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 33 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pluginGroup = me.rafaelldi.aspire
pluginName = aspire-plugin
pluginRepositoryUrl = https://github.com/rafaelldi/aspire-plugin
# SemVer format -> https://semver.org
pluginVersion = 0.2.2
pluginVersion = 0.2.3

# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
pluginSinceBuild = 233
Expand Down
51 changes: 19 additions & 32 deletions src/dotnet/aspire-session-host/Otel/OtelTraceService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,39 +46,24 @@ private void ReportSpans(string serviceName, string scopeName, RepeatedField<Spa
logger.LogTrace("Span received ({otelSpanName}, {otelSpanId}, {otelParentSpanIdId})",
span.Name, spanId, parentSpanId);

string nodeId;
Dictionary<string, string> attributes;
switch (scopeName)
var nodeId = scopeName switch
{
case "Microsoft.AspNetCore":
var (aspNetMethod, aspNetTarget) = GetAspNetCoreMethodAndTarget(span.Attributes);
nodeId = $"{aspNetMethod}-{aspNetTarget}";
attributes = new Dictionary<string, string>
{
{ "http.method", aspNetMethod ?? "" },
{ "http.target", aspNetTarget ?? "" }
};
break;
case "System.Net.Http":
var (httpMethod, httpUrl) = GetNetHttpMethodAndUrl(span.Attributes);
nodeId = $"{httpMethod}-{httpUrl}";
attributes = new Dictionary<string, string>
{
{ "http.method", httpMethod ?? "" },
{ "http.url", httpUrl ?? "" }
};
break;
default:
nodeId = $"{serviceName}-{span.Name}";
attributes = new Dictionary<string, string>();
break;
"Microsoft.AspNetCore" => GetAspNetCoreNodeId(serviceName, span.Attributes),
"System.Net.Http" => GetNetHttpNodeId(serviceName, span.Attributes),
_ => $"{serviceName}-{span.Name}"
};

var attributes = new Dictionary<string, string>(span.Attributes.Count);
foreach (var attribute in span.Attributes)
{
attributes[attribute.Key] = attribute.Value.StringValue;
}

nodeService.ReportTrace(nodeId, span.Name, serviceName, spanId, parentSpanId, attributes);
}
}

private (string? Method, string? Target) GetAspNetCoreMethodAndTarget(RepeatedField<KeyValue> attributes)
private string GetAspNetCoreNodeId(string service, RepeatedField<KeyValue> attributes)
{
string? method = null;
string? target = null;
Expand All @@ -89,12 +74,13 @@ private void ReportSpans(string serviceName, string scopeName, RepeatedField<Spa
if (attribute.Key == "http.target") target = attribute.Value.StringValue;
}

logger.LogTrace("Span Microsoft.AspNetCore attributes {otelSpanHttpMethod} and {otelSpanHttpTarget}", method, target);
logger.LogTrace("Span Microsoft.AspNetCore attributes {otelSpanHttpMethod} and {otelSpanHttpTarget}",
method, target);

return (method, target);
return $"{service}-{method}-{target}";
}

private (string? Method, string? Url) GetNetHttpMethodAndUrl(RepeatedField<KeyValue> attributes)
private string GetNetHttpNodeId(string service, RepeatedField<KeyValue> attributes)
{
string? method = null;
string? url = null;
Expand All @@ -105,8 +91,9 @@ private void ReportSpans(string serviceName, string scopeName, RepeatedField<Spa
if (attribute.Key == "http.url") url = attribute.Value.StringValue;
}

logger.LogTrace("Span System.Net.Http attributes {otelSpanHttpMethod} and {otelSpanHttpUrl}", method, url);
logger.LogTrace("Span System.Net.Http attributes {otelSpanHttpMethod} and {otelSpanHttpUrl}",
method, url);

return (method, url);
return $"{service}-{method}-{url}";
}
}
}

0 comments on commit 378d1aa

Please sign in to comment.