Skip to content

Commit

Permalink
add support for abstract domain sockets in OpenTelemetry.Exporter.Gen…
Browse files Browse the repository at this point in the history
…eva (#1199)
  • Loading branch information
cataggar committed May 31, 2023
1 parent 9fab3ed commit 81364e6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/OpenTelemetry.Exporter.Geneva/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* TldLogExporter to export `SpanId` value in `ext_dt_spanId` field instead of
`TraceId` value.
([#1184](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1184))
* Add support for abstract domain sockets.
([#1199](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/pull/1199))

## 1.5.0-alpha.3

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,29 @@ public TransportProtocol Protocol
}
}

/// <summary>
/// Replace first charater of string if it matches with <paramref name="oldChar"/> with <paramref name="newChar"/>.
/// </summary>
/// <param name="str">String to be updated.</param>
/// <param name="oldChar">Old character to be replaced.</param>
/// <param name="newChar">New character to be replaced with.</param>
/// <returns>Updated string.</returns>
internal static string ReplaceFirstChar(string str, char oldChar, char newChar)
{
if (str.Length > 0 && str[0] == oldChar)
{
return $"{newChar}{str.Substring(1)}";
}

return str;
}

public string ParseUnixDomainSocketPath()
{
try
{
var endpoint = new Uri(this.Endpoint);
return endpoint.AbsolutePath;
return ReplaceFirstChar(endpoint.AbsolutePath, '@', '\0');
}
catch (UriFormatException ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ public void ConnectionStringBuilder_Endpoint_UnixDomainSocketPath()

builder = new ConnectionStringBuilder("EtwSession=OpenTelemetry");
Assert.Throws<ArgumentException>(() => _ = builder.ParseUnixDomainSocketPath());

builder = new ConnectionStringBuilder("Endpoint=unix:@/var/run/default_fluent.socket");
Assert.Equal("unix:@/var/run/default_fluent.socket", builder.Endpoint);
Assert.Equal(TransportProtocol.Unix, builder.Protocol);
Assert.Equal("\0/var/run/default_fluent.socket", builder.ParseUnixDomainSocketPath());
}

[Fact]
Expand Down

0 comments on commit 81364e6

Please sign in to comment.