-
Notifications
You must be signed in to change notification settings - Fork 335
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
Add ActivitySource #1036
Labels
Milestone
Comments
This was referenced Sep 18, 2021
Hello @bgrainger , I have a question, after supporting ActivitySource, can we listen the transaction commit and rollback event in ActivityListener? Thanks |
Those events aren't yet formalised in this proposal but would be obvious next candidates for publishing as an |
Available in 2.0.0-beta.5. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Proposal
ADO.NET libraries should be instrumented with the
ActivitySource
API.This document is based on the Instrumenting a library/application with .NET Activity API recommendations from OpenTelemetry.
Basics
Install v5.0.1 or later of the System.Diagnostics.DiagnosticSource NuGet package.
Create a single
ActivitySource
named after the assembly name of the library being instrumented:Activities
The
ActivityKind
MUST be set toActivityKind.Client
.The standard activity names are:
Open
- establishing a connection to a database serverActivity
.Execute
- executing a command<db.operation> <db.name>.<db.sql.table>
,<db.operation> <db.name>
, or<db.name>
. Since those values will already be set as custom tags on theActivity
, anActivityListener
that is reportingActivity
objects to an OpenTelemetry endpoint should override the span name (with the values of those tags) if desired.ExecuteScalar
,ExecuteNonQuery
, andExecuteReader
as different activities.Execute
activity ends when theDbDataReader
returned byExecuteReader
is closed/disposed.AddEvent
will be used to record when the first response is returned by the server. For MySqlConnector, the event name isread-result-set-header
, and can occur multiple times during an activity if multiple result sets are read. For Npgsql, the event name isreceived-first-response
.Commit
- committing a transactionRollback
- rolling back a transactionFuture activity names may include the following. These should not be used until formalized by this specification.
Close
- closing a database connectionPrepare
- preparing a statementTags
These tags are taken from the OpenTelemetry Semantic Conventions; that document is the authoritative source and should take precedence in case of a conflict with the recommendations here.
db.system
mysql
,postgresql
,other_sql
db.connection_string
Persist Security Info = true
.)Server=dbserver; Database=mydb; User ID=myuser
db.connection_id
173
db.user
myuser
net.peer.name
DbConnection.DataSource
.dbserver
net.peer.ip
127.0.0.1
net.peer.port
1433
,3306
net.transport
ip_tcp
,inproc
db.name
DbConnection.Database
.customers
;main
db.statement
DbCommand.CommandText
. [3]SELECT * FROM example_table;
db.operation
SELECT
,INSERT
db.sql.table
public.users
;customers
thread.id
Thread.CurrentThread.ManagedThreadId
.42
thread.name
Thread.CurrentThread.Name
.Worker Thread
exception.type
ExampleLib.ExampleDbException
exception.message
The exception message.
Could not connect to remote server
exception.stacktrace
net.peer.name
ornet.peer.ip
should be specified.db.statement
just to get this property, but it should be set if the operation name is provided by the library being instrumented. If the SQL statement has an ambiguous operation, or performs more than one operation, this value may be omitted.db.statement
just to get this property, but it should be set if it is provided by the library being instrumented. If the operation is acting upon an anonymous table, or more than one table, this value MUST NOT be set.exception.type
andexception.message
is required.Exceptions
If an exception occurs, the
Status
should be set toActivityStatusCode.Error
and the exception details should be added as an event namedexception
, as per https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/api.md#record-exception.Example
The text was updated successfully, but these errors were encountered: