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

add support for abstract domain sockets in OpenTelemetry.Exporter.Geneva #1199

Merged
merged 13 commits into from
May 31, 2023
Merged
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
utpilla marked this conversation as resolved.
Show resolved Hide resolved
([#1198](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/issues/1198))
utpilla marked this conversation as resolved.
Show resolved Hide resolved

## 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