openai/openai-dotnet

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
fe4d6cf1ccfea48fa5c2baf67103495ac9b459dd

Branches

Tags

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

Clone

HTTPS

Download ZIP

OpenAI/src/Utility/Telemetry/OpenTelemetrySource.cs

30lines · modecode

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