Skip to content
Open
Changes from all commits
Commits
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
88 changes: 88 additions & 0 deletions src/MySqlConnector/Diagnostics/SemconvAttributes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// src/MySqlConnector/Diagnostics/SemconvAttributes.cs
using System.Diagnostics;

namespace MySqlConnector.Diagnostics
{
internal static class SemconvAttributes
{
public static void SetNetworkPeer(Activity activity, string host, int? port, string sockFamily = null, string transport = null)

Check failure on line 8 in src/MySqlConnector/Diagnostics/SemconvAttributes.cs

View check run for this annotation

Azure Pipelines / mysql-net.MySqlConnector (Linux Build)

src/MySqlConnector/Diagnostics/SemconvAttributes.cs#L8

src/MySqlConnector/Diagnostics/SemconvAttributes.cs(8,106): Error CS8625: Cannot convert null literal to non-nullable reference type.

Check failure on line 8 in src/MySqlConnector/Diagnostics/SemconvAttributes.cs

View check run for this annotation

Azure Pipelines / mysql-net.MySqlConnector (Linux Build)

src/MySqlConnector/Diagnostics/SemconvAttributes.cs#L8

src/MySqlConnector/Diagnostics/SemconvAttributes.cs(8,131): Error CS8625: Cannot convert null literal to non-nullable reference type.

Check failure on line 8 in src/MySqlConnector/Diagnostics/SemconvAttributes.cs

View check run for this annotation

Azure Pipelines / mysql-net.MySqlConnector

src/MySqlConnector/Diagnostics/SemconvAttributes.cs#L8

src/MySqlConnector/Diagnostics/SemconvAttributes.cs(8,106): Error CS8625: Cannot convert null literal to non-nullable reference type.

Check failure on line 8 in src/MySqlConnector/Diagnostics/SemconvAttributes.cs

View check run for this annotation

Azure Pipelines / mysql-net.MySqlConnector

src/MySqlConnector/Diagnostics/SemconvAttributes.cs#L8

src/MySqlConnector/Diagnostics/SemconvAttributes.cs(8,131): Error CS8625: Cannot convert null literal to non-nullable reference type.

Check failure on line 8 in src/MySqlConnector/Diagnostics/SemconvAttributes.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Cannot convert null literal to non-nullable reference type.

Check failure on line 8 in src/MySqlConnector/Diagnostics/SemconvAttributes.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Cannot convert null literal to non-nullable reference type.

Check failure on line 8 in src/MySqlConnector/Diagnostics/SemconvAttributes.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Cannot convert null literal to non-nullable reference type.

Check failure on line 8 in src/MySqlConnector/Diagnostics/SemconvAttributes.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Cannot convert null literal to non-nullable reference type.
{
if (activity == null) return;

if (SemconvConfig.EmitOld)

Check failure on line 12 in src/MySqlConnector/Diagnostics/SemconvAttributes.cs

View check run for this annotation

Azure Pipelines / mysql-net.MySqlConnector (Linux Build)

src/MySqlConnector/Diagnostics/SemconvAttributes.cs#L12

src/MySqlConnector/Diagnostics/SemconvAttributes.cs(12,17): Error CS0103: The name 'SemconvConfig' does not exist in the current context

Check failure on line 12 in src/MySqlConnector/Diagnostics/SemconvAttributes.cs

View check run for this annotation

Azure Pipelines / mysql-net.MySqlConnector

src/MySqlConnector/Diagnostics/SemconvAttributes.cs#L12

src/MySqlConnector/Diagnostics/SemconvAttributes.cs(12,17): Error CS0103: The name 'SemconvConfig' does not exist in the current context

Check failure on line 12 in src/MySqlConnector/Diagnostics/SemconvAttributes.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

The name 'SemconvConfig' does not exist in the current context
{
if (!string.IsNullOrEmpty(host)) activity.SetTag("net.peer.name", host);
if (port.HasValue) activity.SetTag("net.peer.port", port.Value);
if (!string.IsNullOrEmpty(sockFamily)) activity.SetTag("net.sock.family", sockFamily);
if (!string.IsNullOrEmpty(transport)) activity.SetTag("net.transport", transport);
// net.sock.peer.addr / net.sock.peer.port / net.sock.* could be set if IP addr/socket known
}

if (SemconvConfig.EmitNew)

Check failure on line 21 in src/MySqlConnector/Diagnostics/SemconvAttributes.cs

View check run for this annotation

Azure Pipelines / mysql-net.MySqlConnector (Linux Build)

src/MySqlConnector/Diagnostics/SemconvAttributes.cs#L21

src/MySqlConnector/Diagnostics/SemconvAttributes.cs(21,17): Error CS0103: The name 'SemconvConfig' does not exist in the current context

Check failure on line 21 in src/MySqlConnector/Diagnostics/SemconvAttributes.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

The name 'SemconvConfig' does not exist in the current context
{
if (!string.IsNullOrEmpty(host)) activity.SetTag("server.address", host);
if (port.HasValue) activity.SetTag("server.port", port.Value);
// network.peer.address = host or IP
if (!string.IsNullOrEmpty(host)) activity.SetTag("network.peer.address", host);
if (port.HasValue) activity.SetTag("network.peer.port", port.Value);
// canonicalize transport: map 'ip_tcp' -> 'tcp', 'ip_udp' -> 'udp', etc.
if (!string.IsNullOrEmpty(transport))
activity.SetTag("network.transport", MapTransportToSemconv(transport));
if (!string.IsNullOrEmpty(sockFamily))
activity.SetTag("network.type", MapSockFamilyToNetworkType(sockFamily));
}
}

public static void SetDbAttributes(Activity activity, string dbSystem, string dbUser, string dbName, string dbInstanceId = null)

Check failure on line 36 in src/MySqlConnector/Diagnostics/SemconvAttributes.cs

View check run for this annotation

Azure Pipelines / mysql-net.MySqlConnector (Linux Build)

src/MySqlConnector/Diagnostics/SemconvAttributes.cs#L36

src/MySqlConnector/Diagnostics/SemconvAttributes.cs(36,132): Error CS8625: Cannot convert null literal to non-nullable reference type.

Check failure on line 36 in src/MySqlConnector/Diagnostics/SemconvAttributes.cs

View check run for this annotation

Azure Pipelines / mysql-net.MySqlConnector

src/MySqlConnector/Diagnostics/SemconvAttributes.cs#L36

src/MySqlConnector/Diagnostics/SemconvAttributes.cs(36,132): Error CS8625: Cannot convert null literal to non-nullable reference type.

Check failure on line 36 in src/MySqlConnector/Diagnostics/SemconvAttributes.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Cannot convert null literal to non-nullable reference type.

Check failure on line 36 in src/MySqlConnector/Diagnostics/SemconvAttributes.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

Cannot convert null literal to non-nullable reference type.
{
if (activity == null) return;
if (SemconvConfig.EmitOld)

Check failure on line 39 in src/MySqlConnector/Diagnostics/SemconvAttributes.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

The name 'SemconvConfig' does not exist in the current context
{
if (!string.IsNullOrEmpty(dbSystem)) activity.SetTag("db.system", dbSystem);
if (!string.IsNullOrEmpty(dbUser)) activity.SetTag("db.user", dbUser);
if (!string.IsNullOrEmpty(dbName)) activity.SetTag("db.name", dbName);
// legacy didn't have db.instance.id
}
if (SemconvConfig.EmitNew)

Check failure on line 46 in src/MySqlConnector/Diagnostics/SemconvAttributes.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

The name 'SemconvConfig' does not exist in the current context
{
if (!string.IsNullOrEmpty(dbSystem)) activity.SetTag("db.system", dbSystem);
if (!string.IsNullOrEmpty(dbUser)) activity.SetTag("db.user", dbUser);
if (!string.IsNullOrEmpty(dbName)) activity.SetTag("db.name", dbName);
if (!string.IsNullOrEmpty(dbInstanceId)) activity.SetTag("db.instance.id", dbInstanceId);
}
}

private static string MapTransportToSemconv(string transport)
{
if (string.IsNullOrEmpty(transport)) return transport;
switch (transport.ToLowerInvariant())
{
case "ip_tcp":
case "tcp":
return "tcp";
case "ip_udp":
case "udp":
return "udp";
default:
return transport;
}
}

private static string MapSockFamilyToNetworkType(string family)
{
if (string.IsNullOrEmpty(family)) return family;
switch (family.ToLowerInvariant())
{
case "inet":
case "inet4":
case "ipv4":
return "ipv4";
case "inet6":
case "ipv6":
return "ipv6";
default:
return family;
}
}
}
}
Loading