-
Notifications
You must be signed in to change notification settings - Fork 765
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
update HttpSemanticConventions for Instrumentation.SqlClient #4644
Merged
Merged
Changes from 16 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
990bebb
update semantic conventions for SqlClient
TimothyMothra 7ae8dea
changelog
TimothyMothra f1f6bb9
Merge branch 'main' into 4484_sqlclient
TimothyMothra 7f28305
Merge branch 'main' into 4484_sqlclient
TimothyMothra 6b02100
use variables for new and old
TimothyMothra 0d45854
fix SA1204
TimothyMothra 0e029bc
Update src/OpenTelemetry.Instrumentation.SqlClient/CHANGELOG.md
TimothyMothra f8036f0
update URL to refer to database
TimothyMothra 6fbebbb
Merge branch '4484_sqlclient' of https://github.com/TimothyMothra/ope…
TimothyMothra 7f59ba2
Merge branch 'main' into 4484_sqlclient
TimothyMothra a0cb3b9
revert changelog
TimothyMothra 8c004bf
fix changelog
TimothyMothra 36e54aa
pr feedback
TimothyMothra c95aab0
test
TimothyMothra e492dd1
Merge branch 'main' into 4484_sqlclient
TimothyMothra 70fae06
Merge branch 'main' into 4484_sqlclient
utpilla d462d4f
dupe test method
TimothyMothra 62a4928
commit
TimothyMothra 1e3d202
fix env var
TimothyMothra e4fb26e
correct comment
TimothyMothra cdadb6a
Merge branch 'main' into 4484_sqlclient
utpilla 065b58b
corrected link to spec in comments and changelog
TimothyMothra faa952c
Merge branch 'main' into 4484_sqlclient
TimothyMothra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,8 +32,6 @@ namespace OpenTelemetry.Instrumentation.SqlClient | |
/// </remarks> | ||
public class SqlClientInstrumentationOptions | ||
{ | ||
internal readonly HttpSemanticConvention HttpSemanticConvention; | ||
|
||
/* | ||
* Match... | ||
* protocol[ ]:[ ]serverName | ||
|
@@ -67,6 +65,9 @@ public 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> | ||
|
@@ -79,7 +80,9 @@ internal SqlClientInstrumentationOptions(IConfiguration configuration) | |
{ | ||
Debug.Assert(configuration != null, "configuration was null"); | ||
|
||
this.HttpSemanticConvention = GetSemanticConventionOptIn(configuration); | ||
var httpSemanticConvention = GetSemanticConventionOptIn(configuration); | ||
this.emitOldAttributes = httpSemanticConvention.HasFlag(HttpSemanticConvention.Old); | ||
this.emitNewAttributes = httpSemanticConvention.HasFlag(HttpSemanticConvention.New); | ||
} | ||
|
||
/// <summary> | ||
|
@@ -134,19 +137,23 @@ internal SqlClientInstrumentationOptions(IConfiguration configuration) | |
/// langword="false"/>. | ||
/// </summary> | ||
/// <remarks> | ||
/// <para><b>EnableConnectionLevelAttributes is supported on all | ||
/// runtimes.</b></para> | ||
/// <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> | ||
/// <b>EnableConnectionLevelAttributes is supported on all runtimes.</b> | ||
/// </para> | ||
/// <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). | ||
/// </para> | ||
/// </remarks> | ||
public bool EnableConnectionLevelAttributes { get; set; } | ||
|
||
|
@@ -302,23 +309,45 @@ internal void AddConnectionLevelDetailsToActivity(string dataSource, Activity sq | |
ConnectionDetailCache.TryAdd(dataSource, connectionDetails); | ||
} | ||
|
||
if (!string.IsNullOrEmpty(connectionDetails.ServerHostName)) | ||
{ | ||
sqlActivity.SetTag(SemanticConventions.AttributeNetPeerName, connectionDetails.ServerHostName); | ||
} | ||
else | ||
if (!string.IsNullOrEmpty(connectionDetails.InstanceName)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not related to this PR, but why is this method in the options class instead of the listener? We should probably move this code to the listener. That would also make us consistent with other instrumentation libraries for how we read the environment variable. |
||
{ | ||
sqlActivity.SetTag(SemanticConventions.AttributeNetPeerIp, connectionDetails.ServerIpAddress); | ||
sqlActivity.SetTag(SemanticConventions.AttributeDbMsSqlInstanceName, connectionDetails.InstanceName); | ||
} | ||
|
||
if (!string.IsNullOrEmpty(connectionDetails.InstanceName)) | ||
if (this.emitOldAttributes) | ||
{ | ||
sqlActivity.SetTag(SemanticConventions.AttributeDbMsSqlInstanceName, connectionDetails.InstanceName); | ||
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); | ||
} | ||
} | ||
|
||
if (!string.IsNullOrEmpty(connectionDetails.Port)) | ||
// see the spec https://github.com/open-telemetry/opentelemetry-specification/blob/v1.21.0/specification/trace/semantic_conventions/database.md | ||
if (this.emitNewAttributes) | ||
TimothyMothra marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
sqlActivity.SetTag(SemanticConventions.AttributeNetPeerPort, connectionDetails.Port); | ||
if (!string.IsNullOrEmpty(connectionDetails.ServerHostName)) | ||
{ | ||
sqlActivity.SetTag(SemanticConventions.AttributeServerAddress, connectionDetails.ServerHostName); | ||
} | ||
else | ||
{ | ||
sqlActivity.SetTag(SemanticConventions.AttributeServerSocketAddress, connectionDetails.ServerIpAddress); | ||
} | ||
|
||
if (!string.IsNullOrEmpty(connectionDetails.Port)) | ||
vishweshbankwar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
// TODO: Should we continue to emit this if the default port (1433) is being used? | ||
sqlActivity.SetTag(SemanticConventions.AttributeServerPort, connectionDetails.Port); | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we're lacking clarity here, https://github.com/open-telemetry/opentelemetry-specification/blob/v1.21.0/CHANGELOG.md#v1210-2023-05-09 clearly called out that semconv got moved to a new repo so it doesn't seem to be part of v1.21.0 release, yet we're referring to 1.21.0 database link, what does that mean and what exactly are we trying to follow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was already discussed. #4538 (comment)
The semantic-conventions repo doesn't have any versioned releases for me to link to.
@utpilla asked me to link to the former repo which does have versioned tags to link to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me change the question, which exact semantic convention version do we want to implement in this PR? (I don't think the goal to implement the link that you put here)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want to implement the breaking changes to the HTTP Semantic Conventions.
These changes are described in the v1.21.0 of the opentelemetry-specification.
https://github.com/open-telemetry/opentelemetry-specification/tree/v1.21.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI for all persons here.
Semantic-Conventions repo is readying their first release. The version will be v1.21.0. No ETA because they're building out the processes.
https://github.com/open-telemetry/semantic-conventions/blob/df8e53054147acf49918582bd446d0f524170071/CHANGELOG.md
Trask advised that we should link to "main" for now.
I need some time to update all the comments and links. Will need to create a new PR to correct everything that merged already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI - open-telemetry/semantic-conventions#190