Skip to content
Merged
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
11 changes: 11 additions & 0 deletions sdk/monitor/Azure.Monitor.OpenTelemetry.AspNetCore/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,19 @@

### Bugs Fixed

* Will no longer emit `db.statement_type` as a part of SQL custom dimensions.
This attribute was removed from the SqlClient Instrumentation Library because it's not a part of the [semantic conventions](https://github.com/open-telemetry/semantic-conventions/blob/v1.24.0/docs/database/database-spans.md#call-level-attributes).
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do you want to add PR link at the end?

Copy link
Copy Markdown
Author

@TimothyMothra TimothyMothra Mar 7, 2024

Choose a reason for hiding this comment

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

I'm not clear on how we want to handle this for vendored code. We increase our maintenance load if we want list every major change.

I think a reasonable user could navigate to the otel repo to review changes there.
We can always adapt our strategy here based on feedback.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I'm merging now so I can continue working on following changes.
We can review this again before releasing.


### Other Changes

* Updated the code of vendored instrumentation library `OpenTelemetry.Instrumentation.SqlClient` from the OpenTelemetry .NET repository.
Code has been updated to [1.7.0-beta.1](https://github.com/open-telemetry/opentelemetry-dotnet/tree/Instrumentation.SqlClient-1.7.0-beta.1/src/OpenTelemetry.Instrumentation.SqlClient).
([#42479](https://github.com/Azure/azure-sdk-for-net/pull/42479))

* Updated the code of vendored resource detector library `OpenTelemetry.ResourceDetectors.Azure` from the OpenTelemetry .NET contrib repository.
Code has been updated to [1.0.0-beta.5](https://github.com/open-telemetry/opentelemetry-dotnet-contrib/tree/ResourceDetectors.Azure-1.0.0-beta.5/src/OpenTelemetry.ResourceDetectors.Azure).
([#42479](https://github.com/Azure/azure-sdk-for-net/pull/42479))

## 1.2.0-beta.1 (2024-02-09)

### Features Added
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
// <copyright file="SqlActivitySourceHelper.cs" company="OpenTelemetry Authors">
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

We got advice from CELA last year about how to copy code from an open source repo.
I can't find the email thread right now, but I'll try to find and share.

This line was added to all the vendored files in our original PR. #38848
In THIS PR, I'm trying to bring these other files in line with that original PR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't understand.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

CORRECTION
This line was originally included in the files from the OTel repo.
Reiley removed them in the source files a few months ago. open-telemetry/opentelemetry-dotnet#5140
We should do the same here. I'll create another PR to get this cleaned up.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Now coming to my next question - how do we pull 3rd party code and how do we review these PRs? (it's hard to tell whether the files are the same or there are accidental mistakes during copy/paste).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Our approach should be to copy the entire file, not to compare the text and merge them. I spoke to @TimothyMothra, stating that we need to copy the files instead of comparing the text before the review. I also missed this during the review.

We don’t have a formalized process for review. We will work with the Azure SDK team on the process. Until we find a process, we may need to have a very strict manual review process. (Along with it, we should at least have minimum of 2 approval needed to merge).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Our approach should be to copy the entire file, not to compare the text and merge them. I spoke to @TimothyMothra, stating that we need to copy the files instead of comparing the text before the review. I also missed this during the review.

We don’t have a formalized process for review. We will work with the Azure SDK team on the process. Until we find a process, we may need to have a very strict manual review process. (Along with it, we should at least have minimum of 2 approval needed to merge).

Thanks!

// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
// SPDX-License-Identifier: Apache-2.0

using System.Diagnostics;
using System.Reflection;
using OpenTelemetry.Trace;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
// <copyright file="SqlClientDiagnosticListener.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
// SPDX-License-Identifier: Apache-2.0

#if !NETFRAMEWORK
using System.Data;
using System.Diagnostics;
Expand Down Expand Up @@ -44,12 +33,12 @@ internal sealed class SqlClientDiagnosticListener : ListenerHandler
private readonly PropertyFetcher<CommandType> commandTypeFetcher = new("CommandType");
private readonly PropertyFetcher<object> commandTextFetcher = new("CommandText");
private readonly PropertyFetcher<Exception> exceptionFetcher = new("Exception");
private readonly SqlClientInstrumentationOptions options;
private readonly SqlClientTraceInstrumentationOptions options;

public SqlClientDiagnosticListener(string sourceName, SqlClientInstrumentationOptions options)
public SqlClientDiagnosticListener(string sourceName, SqlClientTraceInstrumentationOptions options)
: base(sourceName)
{
this.options = options ?? new SqlClientInstrumentationOptions();
this.options = options ?? new SqlClientTraceInstrumentationOptions();
}

public override bool SupportsNullActivity => true;
Expand Down Expand Up @@ -120,7 +109,6 @@ public override void OnEventWritten(string name, object payload)
switch (commandType)
{
case CommandType.StoredProcedure:
activity.SetTag(SpanAttributeConstants.DatabaseStatementTypeKey, nameof(CommandType.StoredProcedure));
if (this.options.SetDbStatementForStoredProcedure)
{
activity.SetTag(SemanticConventions.AttributeDbStatement, (string)commandText);
Expand All @@ -129,7 +117,6 @@ public override void OnEventWritten(string name, object payload)
break;

case CommandType.Text:
activity.SetTag(SpanAttributeConstants.DatabaseStatementTypeKey, nameof(CommandType.Text));
if (this.options.SetDbStatementForText)
{
activity.SetTag(SemanticConventions.AttributeDbStatement, (string)commandText);
Expand All @@ -138,7 +125,6 @@ public override void OnEventWritten(string name, object payload)
break;

case CommandType.TableDirect:
activity.SetTag(SpanAttributeConstants.DatabaseStatementTypeKey, nameof(CommandType.TableDirect));
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
// <copyright file="SqlClientInstrumentationEventSource.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
// SPDX-License-Identifier: Apache-2.0

using System.Diagnostics.Tracing;
using OpenTelemetry.Internal;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
// <copyright file="SqlEventSourceListener.netfx.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
// SPDX-License-Identifier: Apache-2.0

#if NETFRAMEWORK
using System.Diagnostics;
Expand Down Expand Up @@ -42,13 +30,13 @@ internal sealed class SqlEventSourceListener : EventListener
internal const int BeginExecuteEventId = 1;
internal const int EndExecuteEventId = 2;

private readonly SqlClientInstrumentationOptions options;
private readonly SqlClientTraceInstrumentationOptions options;
private EventSource adoNetEventSource;
private EventSource mdsEventSource;

public SqlEventSourceListener(SqlClientInstrumentationOptions options = null)
public SqlEventSourceListener(SqlClientTraceInstrumentationOptions options = null)
{
this.options = options ?? new SqlClientInstrumentationOptions();
this.options = options ?? new SqlClientTraceInstrumentationOptions();
}

public override void Dispose()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
// <copyright file="SqlClientInstrumentation.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
// SPDX-License-Identifier: Apache-2.0

#if NET6_0_OR_GREATER
using System.Diagnostics.CodeAnalysis;
Expand Down Expand Up @@ -57,7 +45,7 @@ internal sealed class SqlClientInstrumentation : IDisposable
[RequiresUnreferencedCode(SqlClientTrimmingUnsupportedMessage)]
#endif
public SqlClientInstrumentation(
SqlClientInstrumentationOptions options = null)
SqlClientTraceInstrumentationOptions options = null)
{
#if NETFRAMEWORK
this.sqlEventSourceListener = new SqlEventSourceListener(options);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,12 @@
// <copyright file="SqlClientInstrumentationOptions.cs" company="OpenTelemetry Authors">
// <copyright file="SqlClientTraceInstrumentationOptions.cs" company="OpenTelemetry Authors">
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
// SPDX-License-Identifier: Apache-2.0

using System.Collections.Concurrent;
using System.Data;
using System.Diagnostics;
using System.Text.RegularExpressions;
using Microsoft.Extensions.Configuration;
using OpenTelemetry.Trace;
using static OpenTelemetry.Internal.HttpSemanticConventionHelper;

namespace OpenTelemetry.Instrumentation.SqlClient;

Expand All @@ -30,7 +16,7 @@ namespace OpenTelemetry.Instrumentation.SqlClient;
/// <remarks>
/// For help and examples see: <a href="https://github.com/open-telemetry/opentelemetry-dotnet/tree/main/src/OpenTelemetry.Instrumentation.SqlClient/README.md#advanced-configuration" />.
/// </remarks>
internal class SqlClientInstrumentationOptions
internal class SqlClientTraceInstrumentationOptions
{
/*
* Match...
Expand Down Expand Up @@ -65,26 +51,6 @@ internal class SqlClientInstrumentationOptions

private static readonly ConcurrentDictionary<string, SqlConnectionDetails> ConnectionDetailCache = new(StringComparer.OrdinalIgnoreCase);

private readonly bool emitOldAttributes;
private readonly bool emitNewAttributes;

/// <summary>
/// Initializes a new instance of the <see cref="SqlClientInstrumentationOptions"/> class.
/// </summary>
public SqlClientInstrumentationOptions()
: this(new ConfigurationBuilder().AddEnvironmentVariables().Build())
{
}

internal SqlClientInstrumentationOptions(IConfiguration configuration)
{
Debug.Assert(configuration != null, "configuration was null");

var httpSemanticConvention = GetSemanticConventionOptIn(configuration);
this.emitOldAttributes = httpSemanticConvention.HasFlag(HttpSemanticConvention.Old);
this.emitNewAttributes = httpSemanticConvention.HasFlag(HttpSemanticConvention.New);
}

/// <summary>
/// Gets or sets a value indicating whether or not the <see
/// cref="SqlClientInstrumentation"/> should add the names of <see
Expand Down Expand Up @@ -143,13 +109,6 @@ internal SqlClientInstrumentationOptions(IConfiguration configuration)
/// <para>
/// The default behavior is to set the SqlConnection DataSource as the <see cref="SemanticConventions.AttributePeerService"/> tag.
/// If enabled, SqlConnection DataSource will be parsed and the server name will be sent as the
/// <see cref="SemanticConventions.AttributeNetPeerName"/> or <see cref="SemanticConventions.AttributeNetPeerIp"/> tag,
/// the instance name will be sent as the <see cref="SemanticConventions.AttributeDbMsSqlInstanceName"/> tag,
/// and the port will be sent as the <see cref="SemanticConventions.AttributeNetPeerPort"/> tag if it is not 1433 (the default port).
/// </para>
/// <para>
/// If the environment variable OTEL_SEMCONV_STABILITY_OPT_IN is set to "http", the newer Semantic Convention v1.21.0 Attributes will be emitted.
/// SqlConnection DataSource will be parsed and the server name will be sent as the
/// <see cref="SemanticConventions.AttributeServerAddress"/> or <see cref="SemanticConventions.AttributeServerSocketAddress"/> tag,
/// the instance name will be sent as the <see cref="SemanticConventions.AttributeDbMsSqlInstanceName"/> tag,
/// and the port will be sent as the <see cref="SemanticConventions.AttributeServerPort"/> tag if it is not 1433 (the default port).
Expand Down Expand Up @@ -314,40 +273,19 @@ internal void AddConnectionLevelDetailsToActivity(string dataSource, Activity sq
sqlActivity.SetTag(SemanticConventions.AttributeDbMsSqlInstanceName, connectionDetails.InstanceName);
}

if (this.emitOldAttributes)
if (!string.IsNullOrEmpty(connectionDetails.ServerHostName))
{
if (!string.IsNullOrEmpty(connectionDetails.ServerHostName))
{
sqlActivity.SetTag(SemanticConventions.AttributeNetPeerName, connectionDetails.ServerHostName);
}
else
{
sqlActivity.SetTag(SemanticConventions.AttributeNetPeerIp, connectionDetails.ServerIpAddress);
}

if (!string.IsNullOrEmpty(connectionDetails.Port))
{
sqlActivity.SetTag(SemanticConventions.AttributeNetPeerPort, connectionDetails.Port);
}
sqlActivity.SetTag(SemanticConventions.AttributeServerAddress, connectionDetails.ServerHostName);
}

// see the spec https://github.com/open-telemetry/semantic-conventions/blob/v1.21.0/docs/database/database-spans.md
if (this.emitNewAttributes)
else
{
if (!string.IsNullOrEmpty(connectionDetails.ServerHostName))
{
sqlActivity.SetTag(SemanticConventions.AttributeServerAddress, connectionDetails.ServerHostName);
}
else
{
sqlActivity.SetTag(SemanticConventions.AttributeServerSocketAddress, connectionDetails.ServerIpAddress);
}
sqlActivity.SetTag(SemanticConventions.AttributeServerSocketAddress, connectionDetails.ServerIpAddress);
}

if (!string.IsNullOrEmpty(connectionDetails.Port))
{
// TODO: Should we continue to emit this if the default port (1433) is being used?
sqlActivity.SetTag(SemanticConventions.AttributeServerPort, connectionDetails.Port);
}
if (!string.IsNullOrEmpty(connectionDetails.Port))
{
// TODO: Should we continue to emit this if the default port (1433) is being used?
sqlActivity.SetTag(SemanticConventions.AttributeServerPort, connectionDetails.Port);
}
}
}
Expand Down
Loading