-
Notifications
You must be signed in to change notification settings - Fork 856
Added instrumentation for netfx SqlClient. #761
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
Changes from all commits
06978ba
40dd3b1
fb25ff8
401f740
dade046
baa5f1b
14c399d
c3a499c
83200ea
7e62d1b
b9908b8
e9ac05e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,9 +40,10 @@ public static class SpanAttributeConstants | |
| public const string HttpRouteKey = "http.route"; | ||
| public const string HttpFlavorKey = "http.flavor"; | ||
|
|
||
| public const string DatabaseTypeKey = "db.type"; | ||
| public const string DatabaseInstanceKey = "db.instance"; | ||
| public const string DatabaseSystemKey = "db.system"; | ||
|
Member
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.
Member
Author
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. Created #782 for this. |
||
| public const string DatabaseNameKey = "db.name"; | ||
| public const string DatabaseStatementKey = "db.statement"; | ||
| public const string DatabaseStatementTypeKey = "db.statement_type"; | ||
|
Member
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. Is this part of spec?
Member
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. Oh I now recollect we already discussed this. Will need to follow up on spec. Note to myself! |
||
|
|
||
| public const string RpcSystem = "rpc.system"; | ||
| public const string RpcService = "rpc.service"; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,6 @@ | |
| using System.Data; | ||
| using System.Diagnostics; | ||
| using OpenTelemetry.Trace; | ||
| using OpenTelemetry.Trace.Samplers; | ||
|
|
||
| namespace OpenTelemetry.Instrumentation.Dependencies.Implementation | ||
| { | ||
|
|
@@ -32,7 +31,7 @@ internal class SqlClientDiagnosticListener : ListenerHandler | |
| internal const string SqlDataWriteCommandError = "System.Data.SqlClient.WriteCommandError"; | ||
| internal const string SqlMicrosoftWriteCommandError = "Microsoft.Data.SqlClient.WriteCommandError"; | ||
|
|
||
| private const string DatabaseStatementTypeSpanAttributeKey = "db.statementType"; | ||
| internal const string MicrosoftSqlServerDatabaseSystemName = "mssql"; | ||
|
|
||
| private readonly PropertyFetcher commandFetcher = new PropertyFetcher("Command"); | ||
| private readonly PropertyFetcher connectionFetcher = new PropertyFetcher("Connection"); | ||
|
|
@@ -66,7 +65,7 @@ public override void OnCustom(string name, Activity activity, object payload) | |
|
|
||
| if (command == null) | ||
| { | ||
| InstrumentationEventSource.Log.NullPayload($"{nameof(SqlClientDiagnosticListener)}-{name}"); | ||
| InstrumentationEventSource.Log.NullPayload(nameof(SqlClientDiagnosticListener), name); | ||
| return; | ||
| } | ||
|
|
||
|
|
@@ -85,17 +84,16 @@ public override void OnCustom(string name, Activity activity, object payload) | |
| var commandText = this.commandTextFetcher.Fetch(command); | ||
|
|
||
| activity.AddTag(SpanAttributeConstants.ComponentKey, "sql"); | ||
| activity.AddTag(SpanAttributeConstants.DatabaseTypeKey, "sql"); | ||
| activity.AddTag(SpanAttributeConstants.DatabaseSystemKey, MicrosoftSqlServerDatabaseSystemName); | ||
| activity.AddTag(SpanAttributeConstants.PeerServiceKey, (string)dataSource); | ||
| activity.AddTag(SpanAttributeConstants.DatabaseInstanceKey, (string)database); | ||
| activity.AddTag(SpanAttributeConstants.DatabaseNameKey, (string)database); | ||
|
|
||
| if (this.commandTypeFetcher.Fetch(command) is CommandType commandType) | ||
| { | ||
| activity.AddTag(DatabaseStatementTypeSpanAttributeKey, commandType.ToString()); | ||
|
Member
Author
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. This change was made to avoid the
Member
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. :D I read this comment late, and was still trying to figure out this part ! |
||
|
|
||
| switch (commandType) | ||
| { | ||
| case CommandType.StoredProcedure: | ||
| activity.AddTag(SpanAttributeConstants.DatabaseStatementTypeKey, nameof(CommandType.StoredProcedure)); | ||
| if (this.options.CaptureStoredProcedureCommandName) | ||
| { | ||
| activity.AddTag(SpanAttributeConstants.DatabaseStatementKey, (string)commandText); | ||
|
|
@@ -104,12 +102,17 @@ public override void OnCustom(string name, Activity activity, object payload) | |
| break; | ||
|
|
||
| case CommandType.Text: | ||
| activity.AddTag(SpanAttributeConstants.DatabaseStatementTypeKey, nameof(CommandType.Text)); | ||
| if (this.options.CaptureTextCommandContent) | ||
| { | ||
| activity.AddTag(SpanAttributeConstants.DatabaseStatementKey, (string)commandText); | ||
| } | ||
|
|
||
| break; | ||
|
|
||
| case CommandType.TableDirect: | ||
| activity.AddTag(SpanAttributeConstants.DatabaseStatementTypeKey, nameof(CommandType.TableDirect)); | ||
| break; | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -136,7 +139,7 @@ public override void OnCustom(string name, Activity activity, object payload) | |
| } | ||
| else | ||
| { | ||
| InstrumentationEventSource.Log.NullPayload($"{nameof(SqlClientDiagnosticListener)}-{name}"); | ||
| InstrumentationEventSource.Log.NullPayload(nameof(SqlClientDiagnosticListener), name); | ||
| } | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.