Skip to content

OpenAI component doesn't setup telemetry correctly #5451

@samsp-msft

Description

@samsp-msft

I have been fiddling with the playground sample for the playground OpenAI component trying to get it to emit telemetry. I think the following things are missing;

  • Updating Directory.Packages.props to use beta3 for the Azure.AI.OpenAI package
<PackageVersion Include="Azure.AI.OpenAI" Version="2.0.0-beta.3" />

I also had to add a source to nuget as that version is pulling in a more recent OpenAI SDK version than is available internally at the moment

  • In the Aspire.Azure.AI.OpenAI component:
    • Update the activity source names to include OpenAI.*
protected virtual string[] ActivitySourceNames => new[] { $"{typeof(TClient).Namespace}.*", "OpenAI.*" }; 
  • Set the app context switch for the OpenAI instrumentation
        if (GetTracingEnabled(settings))
        {
            AppContext.SetSwitch("OpenAI.Experimental.EnableOpenTelemetry", true);
            builder.Services.AddOpenTelemetry()
                .WithTracing(traceBuilder => traceBuilder.AddSource(ActivitySourceNames));

        }

When these are all in place, we get the metrics and telemetry that @lmolkova added to OpenAI recently.

image

I believe we should include the app context switch - its there because the semanic conventions are not stable, but IMHO for Aspire we should be showing what's available rather than hiding it.

Metadata

Metadata

Labels

aiarea-integrationsIssues pertaining to Aspire Integrations packages

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions