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

fix(EntityFrameworkCore): server.address field to follow otel conventions #2439

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System.Diagnostics;
using OpenTelemetry.Trace;
using Xunit;

namespace OpenTelemetry.Instrumentation.EntityFrameworkCore.Tests;

public class EntityFrameworkInstrumentationTests
{
[Fact]
public void ServerAddressWithoutProtocolPrefix()
{
var activity = new Activity("TestActivity");
activity.Start();

var connection = new
{
Host = "my.domain.example",
DataSource = "tcp:my.domain.example",
Port = "5432"
};

var hostFetcher = new PropertyFetcher<string>("Host");
var dataSourceFetcher = new PropertyFetcher<string>("DataSource");
var portFetcher = new PropertyFetcher<string>("Port");

var host = hostFetcher.Fetch(connection);
if (!string.IsNullOrEmpty(host))
{
activity.AddTag("server.address", host);
}
else
{
var dataSource = dataSourceFetcher.Fetch(connection);
if (!string.IsNullOrEmpty(dataSource))
{
activity.AddTag("server.address", dataSource);
}
}

var port = portFetcher.Fetch(connection);
if (!string.IsNullOrEmpty(port))
{
activity.AddTag("server.port", port);
}

activity.Stop();

Assert.Equal("my.domain.example", activity.Tags.FirstOrDefault(t => t.Key == "server.address").Value);
Assert.Equal("5432", activity.Tags.FirstOrDefault(t => t.Key == "server.port").Value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

* Fixed the `server.address` field in EntityFrameworkCore spans to populate with the server domain name without the `tcp` prefix.

Check failure on line 5 in src/OpenTelemetry.Instrumentation.EntityFrameworkCore/CHANGELOG.md

View workflow job for this annotation

GitHub Actions / lint-md / run-markdownlint

Line length

src/OpenTelemetry.Instrumentation.EntityFrameworkCore/CHANGELOG.md:5:81 MD013/line-length Line length [Expected: 80; Actual: 129] https://github.com/DavidAnson/markdownlint/blob/v0.37.2/doc/md013.md
([#IssueNumber](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/issues/IssueNumber))

## 1.10.0-beta.1

Released 2024-Dec-09
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

Comment on lines -1 to -3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is mandatory.

using System.Data;

Check warning on line 1 in src/OpenTelemetry.Instrumentation.EntityFrameworkCore/Implementation/EntityFrameworkDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / lint-dotnet-format / run-dotnet-format

The file header is missing or not located at the top of the file.

Check failure on line 1 in src/OpenTelemetry.Instrumentation.EntityFrameworkCore/Implementation/EntityFrameworkDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-instrumentation-entityframeworkcore / build-test (windows-latest, net462)

The file header is missing or not located at the top of the file. (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1633.md)

Check failure on line 1 in src/OpenTelemetry.Instrumentation.EntityFrameworkCore/Implementation/EntityFrameworkDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-instrumentation-entityframeworkcore / build-test (windows-latest, net462)

The file header is missing or not located at the top of the file. (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1633.md)

Check failure on line 1 in src/OpenTelemetry.Instrumentation.EntityFrameworkCore/Implementation/EntityFrameworkDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-instrumentation-entityframeworkcore / build-test (windows-latest, net8.0)

The file header is missing or not located at the top of the file. (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1633.md)

Check failure on line 1 in src/OpenTelemetry.Instrumentation.EntityFrameworkCore/Implementation/EntityFrameworkDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-instrumentation-entityframeworkcore / build-test (windows-latest, net8.0)

The file header is missing or not located at the top of the file. (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1633.md)

Check failure on line 1 in src/OpenTelemetry.Instrumentation.EntityFrameworkCore/Implementation/EntityFrameworkDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-instrumentation-entityframeworkcore / build-test (windows-latest, net9.0)

The file header is missing or not located at the top of the file. (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1633.md)

Check failure on line 1 in src/OpenTelemetry.Instrumentation.EntityFrameworkCore/Implementation/EntityFrameworkDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-instrumentation-entityframeworkcore / build-test (windows-latest, net9.0)

The file header is missing or not located at the top of the file. (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1633.md)

Check failure on line 1 in src/OpenTelemetry.Instrumentation.EntityFrameworkCore/Implementation/EntityFrameworkDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-instrumentation-entityframeworkcore / build-test (ubuntu-22.04, net8.0)

The file header is missing or not located at the top of the file. (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1633.md)

Check failure on line 1 in src/OpenTelemetry.Instrumentation.EntityFrameworkCore/Implementation/EntityFrameworkDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-instrumentation-entityframeworkcore / build-test (ubuntu-22.04, net8.0)

The file header is missing or not located at the top of the file. (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1633.md)

Check failure on line 1 in src/OpenTelemetry.Instrumentation.EntityFrameworkCore/Implementation/EntityFrameworkDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-instrumentation-entityframeworkcore / build-test (ubuntu-22.04, net9.0)

The file header is missing or not located at the top of the file. (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1633.md)

Check failure on line 1 in src/OpenTelemetry.Instrumentation.EntityFrameworkCore/Implementation/EntityFrameworkDiagnosticListener.cs

View workflow job for this annotation

GitHub Actions / build-test-instrumentation-entityframeworkcore / build-test (ubuntu-22.04, net9.0)

The file header is missing or not located at the top of the file. (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1633.md)
using System.Diagnostics;
using System.Reflection;
using OpenTelemetry.Internal;
Expand Down Expand Up @@ -40,6 +37,8 @@
private readonly PropertyFetcher<CommandType> commandTypeFetcher = new("CommandType");
private readonly PropertyFetcher<string> commandTextFetcher = new("CommandText");
private readonly PropertyFetcher<Exception> exceptionFetcher = new("Exception");
private readonly PropertyFetcher<string> hostFetcher = new("Host");
private readonly PropertyFetcher<string> portFetcher = new("Port");

private readonly EntityFrameworkInstrumentationOptions options;

Expand Down Expand Up @@ -140,10 +139,24 @@
break;
}

var dataSource = (string)this.dataSourceFetcher.Fetch(connection);
if (!string.IsNullOrEmpty(dataSource))
var host = (string)this.hostFetcher.Fetch(connection);
if (!string.IsNullOrEmpty(host))
{
activity.AddTag(AttributeServerAddress, host);
}
else
{
var dataSource = (string)this.dataSourceFetcher.Fetch(connection);
if (!string.IsNullOrEmpty(dataSource))
{
activity.AddTag(AttributeServerAddress, dataSource);
}
}

var port = (string)this.portFetcher.Fetch(connection);
if (!string.IsNullOrEmpty(port))
{
activity.AddTag(AttributeServerAddress, dataSource);
activity.AddTag(AttributeServerAddress, port);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure about attribute name here?

}

if (this.options.EmitOldAttributes)
Expand Down
Loading