-
Notifications
You must be signed in to change notification settings - Fork 900
update HttpSemanticConventions for Instrumentation.SqlClient #4644
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
990bebb
update semantic conventions for SqlClient
7ae8dea
changelog
f1f6bb9
Merge branch 'main' into 4484_sqlclient
7f28305
Merge branch 'main' into 4484_sqlclient
6b02100
use variables for new and old
0d45854
fix SA1204
0e029bc
Update src/OpenTelemetry.Instrumentation.SqlClient/CHANGELOG.md
f8036f0
update URL to refer to database
6fbebbb
Merge branch '4484_sqlclient' of https://github.com/TimothyMothra/ope…
7f59ba2
Merge branch 'main' into 4484_sqlclient
a0cb3b9
revert changelog
8c004bf
fix changelog
36e54aa
pr feedback
c95aab0
test
e492dd1
Merge branch 'main' into 4484_sqlclient
70fae06
Merge branch 'main' into 4484_sqlclient
utpilla d462d4f
dupe test method
62a4928
commit
1e3d202
fix env var
e4fb26e
correct comment
cdadb6a
Merge branch 'main' into 4484_sqlclient
utpilla 065b58b
corrected link to spec in comments and changelog
faa952c
Merge branch 'main' into 4484_sqlclient
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 hidden or 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 hidden or 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 hidden or 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,7 +32,8 @@ namespace OpenTelemetry.Instrumentation.SqlClient | |
| /// </remarks> | ||
| public class SqlClientInstrumentationOptions | ||
| { | ||
| internal readonly HttpSemanticConvention HttpSemanticConvention; | ||
| private readonly bool emitOldAttributes; | ||
| private readonly bool emitNewAttributes; | ||
|
|
||
| /* | ||
| * Match... | ||
|
|
@@ -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> | ||
|
|
@@ -302,23 +305,44 @@ 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)) | ||
|
Contributor
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/http.md | ||
| if (this.emitNewAttributes) | ||
|
TimothyMothra marked this conversation as 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.
|
||
| { | ||
| sqlActivity.SetTag(SemanticConventions.AttributeServerPort, connectionDetails.Port); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.