-
Notifications
You must be signed in to change notification settings - Fork 294
Open
Labels
Description
Is your feature request related to a problem?
- We have a fairly large enterprise solution that we want to begin transferring over to use OTEL instead of AI SDK.
- To avoid a "big bang" updated we are looking to update modules/components individually.
- We aim to standardise passing around the (non-HTTP) distributed traces using an OTEL TraceContext using the built in
ActivityContext
. - This allows OTEL code to use
activitySource.StartActivity(_activityName, ActivityKind.Internal, message.ParentContext ?? default);
- There is no complete equivalent available for the AI SDK.
Describe the solution you'd like.
An overload to TelemetryClient.StartOperation
that accepts the operationName
and a parentActivityContext
similar to StartOperation<T>(string operationName, string operationId, string parentOperationId = null)
or the other equivalents that accept parent Ids, but that correctly unpack the W3C trace context.
Describe alternatives you've considered.
Custom extension method using an Activity similar to service bus documented approach.
public static IOperationHolder<TOperationTelemetry> StartOperation<TOperationTelemetry>(
this TelemetryClient telemetryClient,
string operationName,
ActivityContext? parentContext)
where TOperationTelemetry : OperationTelemetry, new()
{
if (!parentContext.HasValue)
return telemetryClient.StartOperation<TOperationTelemetry>(operationName);
var context = parentContext.Value;
#pragma warning disable CA2000 // Dispose objects before losing scope
var activity = new Activity(operationName)
{
TraceStateString = context.TraceState,
// HasRemoteParent = context.IsRemote (Can't set this without using ActivitySource, but unclear if AI SDK uses it anyway.)
}
.SetParentId(context.TraceId, context.SpanId, context.TraceFlags);
#pragma warning restore CA2000 // Dispose objects before losing scope
return telemetryClient.StartOperation<TOperationTelemetry>(activity);
}