-
Notifications
You must be signed in to change notification settings - Fork 106
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
feat(csharp/src/Apache.Arrow.Adbc): add OpenTelemetry compatible tracing support #2559
base: main
Are you sure you want to change the base?
feat(csharp/src/Apache.Arrow.Adbc): add OpenTelemetry compatible tracing support #2559
Conversation
…ort for AdbcConnection11 and AdbcStatement11
/// <summary> | ||
/// Simplified version of <see cref="Activity"/> that excludes some properties, etc. | ||
/// </summary> | ||
internal class SerializableActivity |
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 class is explicitly necessary, but helps with testing. It also "could" be useful a serialized version of Activity
public override AdbcDatabase Open(IReadOnlyDictionary<string, string> parameters) | ||
{ | ||
return new HiveServer2Database(parameters); | ||
return new HiveServer2Database(parameters, Trace); |
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.
Passing reference to Trace
object to child object for consistent activity source name and handling of trace parent.
activity?.AddEvent("db.operation.name.start", [new("db.operation.name", nameof(Client.FetchResults))]); | ||
TFetchResultsReq request = new TFetchResultsReq(this.statement.OperationHandle, TFetchOrientation.FETCH_NEXT, this.statement.BatchSize); | ||
TFetchResultsResp response = await this.statement.Connection.Client!.FetchResults(request, cancellationToken); | ||
activity?.AddEvent("db.operation.name.end", |
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.
Helps to trace the begin/end of fetching results from the server so the duration can be calculated from the difference.
TGetCatalogsResp getCatalogsResp = Client.GetCatalogs(getCatalogsReq, cancellationToken).Result; | ||
// Since this API only allows non-null values, we'll treat empty string as null to allow the TraceParent to be unset. | ||
case HiveServer2Parameters.TraceParent: | ||
Trace.TraceParent = !string.IsNullOrWhiteSpace(value) |
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.
Allow the caller to set the trace_parent
on the connection.
This PR adds OpenTelemetry-compatible tracing support on the CSharp library.
Under the hood it uses
Activity
andActivitySource
from the netSystem.Diagnostics.DiagnosticSource
package.Create an instance of the
ActivityTrace
object.By default, the
activitySourceName
will be created from the driver assembly name.Then to instrument tracing, use one of the following overrides of
TraceActivity
TraceActivityAsync
Example:
Each of these overrides starts a new
Activity
which will be non-null only if there is an activeActivityListener
orOpenTelemetry
exporter. TheActivity
is passed to the delegate Func/Action in case it need to addActivityEvent
,ActivityLink
orTags
(KeyValuePair
). When instrumenting tracing, you should always use the null-conditional operator (?.
) when accessing members on the passed delegate parameter,activity
.Example:
The default behavior is to invoke the delegate and if successful (i.e., no exception thrown), the
Activity.SetStatus
is set toOk
. If an exception is observed, then theActivity.SetStatus
is set toError
and the exception is traced (Activity.AddException
) as an event in the currentActivity
.Callers can pass a
traceparent
string to any of the TraceActivity[Async] methods using the optionaltraceParent
parameter. The parameter takes precedence over the property. ThetraceId
from thetraceParent
parameter orTraceParent
property will be adopted as therootId
for all trace Activity on that call or object. IfTraceParent
is null (initial or set later), then theActivity
creates a newrootId
for the beginning of the initialActivity
in the stack.Example:
Identifiers used for events and tags should follow the OpenTelemetry semantic guidance ..
https://opentelemetry.io/docs/specs/semconv/database/database-spans/
https://opentelemetry.io/docs/specs/semconv/database/database-metrics/