Skip to content

[sql] Implement updates to new semantic conventions for stored procedures#2693

Merged
Kielek merged 5 commits intoopen-telemetry:mainfrom
alanwest:alanwest/db-stored-procedure-name
May 5, 2025
Merged

[sql] Implement updates to new semantic conventions for stored procedures#2693
Kielek merged 5 commits intoopen-telemetry:mainfrom
alanwest:alanwest/db-stored-procedure-name

Conversation

@alanwest
Copy link
Copy Markdown
Member

@alanwest alanwest commented Apr 11, 2025

Implementing the new db.stored_procedure.name attribute.

The db.operation.name, db.collection.name, and db.query.text attributes have been removed when CommandType = StoredProcedure because they are no longer applicable.

Side note, we have an odd scenario for .NET Framework users. CommandType is not known, so db.query.text will still be used even for stored procedures. This requires documentation, but is beyond the scope of this PR.

@alanwest alanwest requested a review from a team as a code owner April 11, 2025 22:03
@github-actions github-actions Bot added the comp:instrumentation.sqlclient Things related to OpenTelemetry.Instrumentation.SqlClient label Apr 11, 2025
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 69.50%. Comparing base (71655ce) to head (c61d3bc).
Report is 824 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2693      +/-   ##
==========================================
- Coverage   73.91%   69.50%   -4.42%     
==========================================
  Files         267      394     +127     
  Lines        9615    15875    +6260     
==========================================
+ Hits         7107    11034    +3927     
- Misses       2508     4841    +2333     
Flag Coverage Δ
unittests-Contrib.Shared.Tests 85.67% <ø> (?)
unittests-Exporter.Geneva 52.84% <ø> (?)
unittests-Exporter.InfluxDB 95.14% <ø> (?)
unittests-Exporter.Instana 74.86% <ø> (?)
unittests-Exporter.OneCollector 94.61% <ø> (?)
unittests-Exporter.Stackdriver 79.26% <ø> (?)
unittests-Extensions 90.65% <ø> (?)
unittests-Extensions.Enrichment 100.00% <ø> (?)
unittests-Instrumentation.AWS 83.83% <ø> (?)
unittests-Instrumentation.AspNet 76.79% <ø> (?)
unittests-Instrumentation.AspNetCore 70.32% <ø> (?)
unittests-Instrumentation.ConfluentKafka 14.10% <ø> (?)
unittests-Instrumentation.ElasticsearchClient 80.12% <ø> (?)
unittests-Instrumentation.EntityFrameworkCore 57.06% <ø> (?)
unittests-Instrumentation.EventCounters 76.36% <ø> (?)
unittests-Instrumentation.GrpcCore 91.42% <ø> (?)
unittests-Instrumentation.GrpcNetClient 79.61% <ø> (?)
unittests-Instrumentation.Hangfire 93.58% <ø> (?)
unittests-Instrumentation.Http 74.09% <ø> (?)
unittests-Instrumentation.Owin 88.41% <ø> (?)
unittests-Instrumentation.Process 100.00% <ø> (?)
unittests-Instrumentation.Quartz 78.76% <ø> (?)
unittests-Instrumentation.Runtime 100.00% <ø> (?)
unittests-Instrumentation.ServiceFabricRemoting 34.54% <ø> (?)
unittests-Instrumentation.SqlClient 87.91% <100.00%> (?)
unittests-Instrumentation.StackExchangeRedis 71.63% <ø> (?)
unittests-Instrumentation.Wcf 78.57% <ø> (?)
unittests-PersistentStorage 65.21% <ø> (?)
unittests-Resources.AWS 75.00% <ø> (?)
unittests-Resources.Azure 84.56% <ø> (?)
unittests-Resources.Container 67.34% <ø> (?)
unittests-Resources.Gcp 71.15% <ø> (?)
unittests-Resources.Host 73.91% <ø> (?)
unittests-Resources.OperatingSystem 76.98% <ø> (?)
unittests-Resources.Process 100.00% <ø> (?)
unittests-Resources.ProcessRuntime 78.26% <ø> (?)
unittests-Sampler.AWS 88.25% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...qlClient/Implementation/SqlActivitySourceHelper.cs 90.76% <100.00%> (ø)
...ient/Implementation/SqlClientDiagnosticListener.cs 86.50% <100.00%> (ø)

... and 392 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

activity.SetTag(SemanticConventions.AttributeDbOperationName, "EXECUTE");
activity.SetTag(SemanticConventions.AttributeDbCollectionName, commandText);
activity.SetTag(SemanticConventions.AttributeDbQueryText, commandText);
activity.SetTag(SemanticConventions.AttributeDbStoredProcedureName, commandText);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@trask @lmolkova @maryliag

Wanted to check with you all to confirm this meets the spirt of the recent changes regarding stored procedures.

  1. Removing db.operation.name. I was arbitrarily setting it to EXECUTE before since there was no "operation" present in the query text.
  2. Removing db.collection.name and db.query.text since their values would simply be the same as db.stored_procedure.name making them redundant.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Also, once I add db.query.summary should db.query.summary = db.stored_procedure.name?

Copy link
Copy Markdown
Member

@trask trask Apr 11, 2025

Choose a reason for hiding this comment

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

db.collection.name shouldn't be captured since it's not a collection

I would expect db.query.text to be captured if the stored proc is run via a query API (where you pass SQL), but from a non-query API where you explicitly pass a stored proc name

db.operation.name is a good question. I think if it's not a query API (where you pass SQL), then we should capture db.operation.name (but I suspect spec may not be clear about this)

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 think Java has a non query API for calling stored procedures

https://docs.oracle.com/javase/8/docs/api/java/sql/Connection.html#prepareCall-java.lang.String-

Copy link
Copy Markdown
Member Author

@alanwest alanwest Apr 11, 2025

Choose a reason for hiding this comment

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

The difference between using the "non-query" vs "query" API when invoking a stored procedure in C# is subtle.

"Non-query API"

This will be the more common way to invoke a stored procedure.

var command = new SqlCommand();
command.CommandType = CommandType.StoredProcedure;
command.CommandText = "some_stored_procedure"
command.Parameters.AddWithValue("@some_parameter", "some value");

This is what I think you're proposing:

db.stored_procedure.name = some_stored_procedure
db.operation.name = EXECUTE or CALL or EXEC or ... maybe this is where the spec could be more clear
db.query.summary = EXECUTE some_stored_procedure (or CALL or EXEC)
db.query.text is not set

"Query API"

This will likely be less common, but still possible.

var command = new SqlCommand();
command.CommandType = CommandType.Text;
command.CommandText = "some_stored_procedure @some_parameter"
command.Parameters.AddWithValue("@some_parameter", "some value");

I guess in this scenario we might only be able to set db.query.text.

db.stored_procedure.name is not set
db.operation.name is not set
db.query.text = some_stored_procedure @some_parameter
db.query.summary = ??? (it might be possible to parse the query text and safely infer that it is likely a stored procedure)

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.

thanks

In this case, should db.query.summary be some_stored_procedure or should it be exec some_stored_procedure?

I'm thinking it should be some_stored_procedure based on:

Instrumentations that support query parsing SHOULD parse the query and extract a
list of operations and targets from the query. It SHOULD set db.query.summary
attribute to the value formatted in the following way:

{operation1} {target1} {operation2} {target2} {target3} ...

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.

  • not filed yet: add operation and collection name to SQL

now filed: open-telemetry/semantic-conventions#2207

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'm thinking it should be some_stored_procedure based on:

hmmm. but the query sent to DB would be EXEC some_stored_procedure and operation.name would be EXEC, so summary should be EXEC some_stored_procedure.

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.

but the query sent to DB would be EXEC some_stored_procedure

the way I understood the discussion above is that in this case:

var command = new SqlCommand();
command.CommandType = CommandType.Text;
command.CommandText = "some_stored_procedure"

the query sent to the DB would just be some_stored_procedure

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

the query sent to the DB would just be some_stored_procedure

Yup, that's correct.

Copy link
Copy Markdown
Contributor

@TimothyMothra TimothyMothra left a comment

Choose a reason for hiding this comment

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

LGTM

@github-actions
Copy link
Copy Markdown
Contributor

This PR was marked stale due to lack of activity. It will be closed in 7 days.

@Kielek Kielek merged commit ba90f97 into open-telemetry:main May 5, 2025
214 of 215 checks passed
@trask
Copy link
Copy Markdown
Member

trask commented May 6, 2025

thanks all 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:instrumentation.sqlclient Things related to OpenTelemetry.Instrumentation.SqlClient

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants