openai/openai-dotnet

Public

mirrored from https://github.com/openai/openai-dotnetAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
OpenAI_2.1.0-beta.1

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/Utility/Telemetry/OpenTelemetrySource.cs

30lines · modeblame

d5b5c604Liudmila Molkova1 years ago1using OpenAI.Chat;
2using System;
3
4namespace OpenAI.Telemetry;
5
6internal class OpenTelemetrySource
7{
8private const string ChatOperationName = "chat";
9private readonly bool IsOTelEnabled = AppContextSwitchHelper
10.GetConfigValue("OpenAI.Experimental.EnableOpenTelemetry", "OPENAI_EXPERIMENTAL_ENABLE_OPEN_TELEMETRY");
11
12private readonly string _serverAddress;
13private readonly int _serverPort;
14private readonly string _model;
15
16public OpenTelemetrySource(string model, Uri endpoint)
17{
18_serverAddress = endpoint.Host;
19_serverPort = endpoint.Port;
20_model = model;
21}
22
23public OpenTelemetryScope StartChatScope(ChatCompletionOptions completionsOptions)
24{
25return IsOTelEnabled
26? OpenTelemetryScope.StartChat(_model, ChatOperationName, _serverAddress, _serverPort, completionsOptions)
27: null;
28}
29
30}