-
Notifications
You must be signed in to change notification settings - Fork 173
feat(csharp/src/Apache.Arrow.Adbc): OpenTelemetry tracing baseline #2847
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): OpenTelemetry tracing baseline #2847
Conversation
|
Perhaps @alexguo-db or @eric-wang-1990 can look at the Databricks-specific changes also? |
CurtHagenlocher
left a comment
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.
Thanks! My main concern at this point is that the Activitys being created in ActivityTrace.cs don't seem to be getting Disposed. But I also have a collection of smaller nits and questions.
csharp/src/Apache.Arrow.Adbc/Tracing/IActivityTracerExtensions.cs
Outdated
Show resolved
Hide resolved
|
@alexguo-db / @eric-wang-1990 |
|
@birschick-bq - will you get a chance to resolve the merge conflicts? |
|
CurtHagenlocher
left a comment
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.
Thanks, looks good to me. Just two small nits to point out.
…pache#2847) This PR adds OpenTelemetry-compatible tracing support on the CSharp library. Under the hood it uses `Activity` and `ActivitySource` from the net `System.Diagnostics.DiagnosticSource` package. Inherit from `TracingConnection` ```csharp public class YourConnection: TracingConnection { public YourConnection(IReadOnlyDictionary<string, string> properties) : base(properties) { } } ``` 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: ```csharp public void Connect(...) { TraceActivity((activity) => { driver.OpenSession(...); }); } ``` Each of these overrides starts a new `Activity` which will be non-null **only** if there is an active `ActivityListener` or `OpenTelemetry` exporter. The `Activity` is passed to the delegate Func/Action in case it need to add `ActivityEvent`, `ActivityLink` or `Tags` (`KeyValuePair`). When instrumenting tracing, you should always use the null-conditional operator (`?.` ) when accessing members on the passed delegate parameter, `activity`. Example: ```csharp public IArrowArrayStream GetObjects(...) { return TraceActivity((activity) => { activity?.AddEvent("db.operation.name.start", [new("db.operation.name", nameof(Client.GetCatalogs))]); var result = driver.GetCatalogs(...); var eventActivity = activity?.AddEvent("db.operation.name.end", [ new("db.operation.name", nameof(Client.GetCatalogs)), new("db.response.status_code", getCatalogsResp.Status.StatusCode.ToString()) ]); return ... }); } ``` The default behavior is to invoke the delegate and if successful (i.e., no exception thrown), the `Activity.SetStatus` is set to `Ok`. If an exception is observed, then the `Activity.SetStatus` is set to `Error` and the exception is traced (`Activity.AddException`) as an event in the current `Activity`. Callers can pass a `traceparent` string to any of the TraceActivity[Async] methods using the optional `traceParent` parameter. The parameter takes precedence over the property. The `traceId` from the `traceParent` parameter or `TraceParent` property will be adopted as the `rootId` for all trace Activity on that call or object. If `TraceParent` is null (initial or set later), then the `Activity` creates a new `rootId` for the beginning of the initial `Activity` in the stack. Example: ```csharp public void Connect(..., string? traceParent = default) { TraceActivity((activity) => { activity?.AddEvent("opensession.start"); var result = driver.OpenSession(...); activity?.AddEvent("opensession.end", ["status", result.Status]); }, traceParent: traceParent); } ``` 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/
This PR adds OpenTelemetry-compatible tracing support on the CSharp library.
Under the hood it uses
ActivityandActivitySourcefrom the netSystem.Diagnostics.DiagnosticSourcepackage.Inherit from
TracingConnectionBy default, the
activitySourceNamewill be created from the driver assembly name.Then to instrument tracing, use one of the following overrides of
TraceActivityTraceActivityAsyncExample:
Each of these overrides starts a new
Activitywhich will be non-null only if there is an activeActivityListenerorOpenTelemetryexporter. TheActivityis passed to the delegate Func/Action in case it need to addActivityEvent,ActivityLinkorTags(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.SetStatusis set toOk. If an exception is observed, then theActivity.SetStatusis set toErrorand the exception is traced (Activity.AddException) as an event in the currentActivity.Callers can pass a
traceparentstring to any of the TraceActivity[Async] methods using the optionaltraceParentparameter. The parameter takes precedence over the property. ThetraceIdfrom thetraceParentparameter orTraceParentproperty will be adopted as therootIdfor all trace Activity on that call or object. IfTraceParentis null (initial or set later), then theActivitycreates a newrootIdfor the beginning of the initialActivityin 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/