openlit 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierrc.json +7 -0
- package/LICENSE +201 -0
- package/README.md +175 -0
- package/eslint.config.mjs +10 -0
- package/package.json +60 -0
- package/src/config.ts +45 -0
- package/src/constant.ts +5 -0
- package/src/helpers.ts +122 -0
- package/src/index.ts +72 -0
- package/src/instrumentation/anthropic/index.ts +59 -0
- package/src/instrumentation/anthropic/wrapper.ts +276 -0
- package/src/instrumentation/index.ts +66 -0
- package/src/instrumentation/openai/index.ts +114 -0
- package/src/instrumentation/openai/wrapper.ts +658 -0
- package/src/semantic-convention.ts +113 -0
- package/src/tracing.ts +59 -0
- package/src/types.ts +48 -0
- package/tsconfig.json +15 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
export default class SemanticConvention {
|
|
2
|
+
// GenAI General
|
|
3
|
+
static GEN_AI_ENDPOINT = 'gen_ai.endpoint';
|
|
4
|
+
static GEN_AI_SYSTEM = 'gen_ai.system';
|
|
5
|
+
static GEN_AI_ENVIRONMENT = 'gen_ai.environment';
|
|
6
|
+
static GEN_AI_APPLICATION_NAME = 'gen_ai.application_name';
|
|
7
|
+
static GEN_AI_TYPE = 'gen_ai.type';
|
|
8
|
+
static GEN_AI_HUB_OWNER = 'gen_ai.hub.owner';
|
|
9
|
+
static GEN_AI_HUB_REPO = 'gen_ai.hub.repo';
|
|
10
|
+
static GEN_AI_RETRIEVAL_SOURCE = 'gen_ai.retrieval.source';
|
|
11
|
+
static GEN_AI_REQUESTS = 'gen_ai.total.requests';
|
|
12
|
+
|
|
13
|
+
// GenAI Request
|
|
14
|
+
static GEN_AI_REQUEST_MODEL = 'gen_ai.request.model';
|
|
15
|
+
static GEN_AI_REQUEST_TEMPERATURE = 'gen_ai.request.temperature';
|
|
16
|
+
static GEN_AI_REQUEST_TOP_P = 'gen_ai.request.top_p';
|
|
17
|
+
static GEN_AI_REQUEST_TOP_K = 'gen_ai.request.top_k';
|
|
18
|
+
static GEN_AI_REQUEST_MAX_TOKENS = 'gen_ai.request.max_tokens';
|
|
19
|
+
static GEN_AI_REQUEST_IS_STREAM = 'gen_ai.request.is_stream';
|
|
20
|
+
static GEN_AI_REQUEST_USER = 'gen_ai.request.user';
|
|
21
|
+
static GEN_AI_REQUEST_SEED = 'gen_ai.request.seed';
|
|
22
|
+
static GEN_AI_REQUEST_FREQUENCY_PENALTY = 'gen_ai.request.frequency_penalty';
|
|
23
|
+
static GEN_AI_REQUEST_PRESENCE_PENALTY = 'gen_ai.request.presence_penalty';
|
|
24
|
+
static GEN_AI_REQUEST_EMBEDDING_FORMAT = 'gen_ai.request.embedding_format';
|
|
25
|
+
static GEN_AI_REQUEST_EMBEDDING_DIMENSION = 'gen_ai.request.embedding_dimension';
|
|
26
|
+
static GEN_AI_REQUEST_TOOL_CHOICE = 'gen_ai.request.tool_choice';
|
|
27
|
+
static GEN_AI_REQUEST_AUDIO_VOICE = 'gen_ai.request.audio_voice';
|
|
28
|
+
static GEN_AI_REQUEST_AUDIO_RESPONSE_FORMAT = 'gen_ai.request.audio_response_format';
|
|
29
|
+
static GEN_AI_REQUEST_AUDIO_SPEED = 'gen_ai.request.audio_speed';
|
|
30
|
+
static GEN_AI_REQUEST_FINETUNE_STATUS = 'gen_ai.request.fine_tune_status';
|
|
31
|
+
static GEN_AI_REQUEST_FINETUNE_MODEL_SUFFIX = 'gen_ai.request.fine_tune_model_suffix';
|
|
32
|
+
static GEN_AI_REQUEST_FINETUNE_MODEL_EPOCHS = 'gen_ai.request.fine_tune_n_epochs';
|
|
33
|
+
static GEN_AI_REQUEST_FINETUNE_MODEL_LRM = 'gen_ai.request.learning_rate_multiplier';
|
|
34
|
+
static GEN_AI_REQUEST_FINETUNE_BATCH_SIZE = 'gen_ai.request.fine_tune_batch_size';
|
|
35
|
+
static GEN_AI_REQUEST_VALIDATION_FILE = 'gen_ai.request.validation_file';
|
|
36
|
+
static GEN_AI_REQUEST_TRAINING_FILE = 'gen_ai.request.training_file';
|
|
37
|
+
|
|
38
|
+
static GEN_AI_REQUEST_IMAGE_SIZE = 'gen_ai.request.image_size';
|
|
39
|
+
static GEN_AI_REQUEST_IMAGE_QUALITY = 'gen_ai.request.image_quality';
|
|
40
|
+
static GEN_AI_REQUEST_IMAGE_STYLE = 'gen_ai.request.image_style';
|
|
41
|
+
|
|
42
|
+
// GenAI Usage
|
|
43
|
+
static GEN_AI_USAGE_PROMPT_TOKENS = 'gen_ai.usage.input_tokens';
|
|
44
|
+
static GEN_AI_USAGE_COMPLETION_TOKENS = 'gen_ai.usage.output_tokens';
|
|
45
|
+
static GEN_AI_USAGE_TOTAL_TOKENS = 'gen_ai.usage.total_tokens';
|
|
46
|
+
static GEN_AI_USAGE_COST = 'gen_ai.usage.cost';
|
|
47
|
+
|
|
48
|
+
// GenAI Response
|
|
49
|
+
static GEN_AI_RESPONSE_ID = 'gen_ai.response.id';
|
|
50
|
+
static GEN_AI_RESPONSE_FINISH_REASON = 'gen_ai.response.finish_reason';
|
|
51
|
+
static GEN_AI_RESPONSE_IMAGE = 'gen_ai.response.image'; // Not used directly in code yet
|
|
52
|
+
static GEN_AI_RESPONSE_IMAGE_SIZE = 'gen_ai.request.image_size';
|
|
53
|
+
static GEN_AI_RESPONSE_IMAGE_QUALITY = 'gen_ai.request.image_quality';
|
|
54
|
+
static GEN_AI_RESPONSE_IMAGE_STYLE = 'gen_ai.request.image_style';
|
|
55
|
+
|
|
56
|
+
// GenAI Content
|
|
57
|
+
static GEN_AI_CONTENT_PROMPT = 'gen_ai.content.prompt';
|
|
58
|
+
static GEN_AI_CONTENT_COMPLETION = 'gen_ai.completion';
|
|
59
|
+
static GEN_AI_CONTENT_REVISED_PROMPT = 'gen_ai.content.revised_prompt';
|
|
60
|
+
|
|
61
|
+
static GEN_AI_TYPE_CHAT = 'chat';
|
|
62
|
+
static GEN_AI_TYPE_EMBEDDING = 'embedding';
|
|
63
|
+
static GEN_AI_TYPE_IMAGE = 'image';
|
|
64
|
+
static GEN_AI_TYPE_AUDIO = 'audio';
|
|
65
|
+
static GEN_AI_TYPE_FINETUNING = 'fine_tuning';
|
|
66
|
+
static GEN_AI_TYPE_VECTORDB = 'vectordb';
|
|
67
|
+
static GEN_AI_TYPE_FRAMEWORK = 'framework';
|
|
68
|
+
|
|
69
|
+
static GEN_AI_SYSTEM_HUGGING_FACE = 'huggingface';
|
|
70
|
+
static GEN_AI_SYSTEM_OPENAI = 'openai';
|
|
71
|
+
static GEN_AI_SYSTEM_AZURE_OPENAI = 'azure_openai';
|
|
72
|
+
static GEN_AI_SYSTEM_ANTHROPIC = 'anthropic';
|
|
73
|
+
static GEN_AI_SYSTEM_COHERE = 'cohere';
|
|
74
|
+
static GEN_AI_SYSTEM_MISTRAL = 'mistral';
|
|
75
|
+
static GEN_AI_SYSTEM_BEDROCK = 'bedrock';
|
|
76
|
+
static GEN_AI_SYSTEM_VERTEXAI = 'vertexai';
|
|
77
|
+
static GEN_AI_SYSTEM_LANGCHAIN = 'langchain';
|
|
78
|
+
|
|
79
|
+
// Vector DB
|
|
80
|
+
static DB_REQUESTS = 'db.total.requests';
|
|
81
|
+
static DB_SYSTEM = 'db.system';
|
|
82
|
+
static DB_SYSTEM_CHROMA = 'chroma';
|
|
83
|
+
static DB_SYSTEM_PINECONE = 'pinecone';
|
|
84
|
+
static DB_COLLECTION_NAME = 'db.collection.name';
|
|
85
|
+
static DB_OPERATION = 'db.operation';
|
|
86
|
+
static DB_OPERATION_CREATE_INDEX = 'create_index';
|
|
87
|
+
static DB_OPERATION_QUERY = 'query';
|
|
88
|
+
static DB_OPERATION_DELETE = 'delete';
|
|
89
|
+
static DB_OPERATION_UPDATE = 'update';
|
|
90
|
+
static DB_OPERATION_UPSERT = 'upsert';
|
|
91
|
+
static DB_OPERATION_GET = 'get';
|
|
92
|
+
static DB_OPERATION_ADD = 'add';
|
|
93
|
+
static DB_OPERATION_PEEK = 'peek';
|
|
94
|
+
static DB_ID_COUNT = 'db.ids_count';
|
|
95
|
+
static DB_VECTOR_COUNT = 'db.vector_count';
|
|
96
|
+
static DB_METADATA_COUNT = 'db.metadatas_count';
|
|
97
|
+
static DB_DOCUMENTS_COUNT = 'db.documents_count';
|
|
98
|
+
static DB_QUERY_LIMIT = 'db.limit';
|
|
99
|
+
static DB_OFFSET = 'db.offset';
|
|
100
|
+
static DB_WHERE_DOCUMENT = 'db.where_document';
|
|
101
|
+
static DB_FILTER = 'db.filter';
|
|
102
|
+
static DB_STATEMENT = 'db.statement';
|
|
103
|
+
static DB_N_RESULTS = 'db.n_results';
|
|
104
|
+
static DB_DELETE_ALL = 'db.delete_all';
|
|
105
|
+
static DB_INDEX_NAME = 'db.create_index.name';
|
|
106
|
+
static DB_INDEX_DIMENSION = 'db.create_index.dimensions';
|
|
107
|
+
static DB_INDEX_METRIC = 'db.create_index.metric';
|
|
108
|
+
static DB_INDEX_SPEC = 'db.create_index.spec';
|
|
109
|
+
static DB_NAMESPACE = 'db.query.namespace';
|
|
110
|
+
static DB_UPDATE_METADATA = 'db.update.metadata';
|
|
111
|
+
static DB_UPDATE_VALUES = 'db.update.values';
|
|
112
|
+
static DB_UPDATE_ID = 'db.update.id';
|
|
113
|
+
}
|
package/src/tracing.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { SetupTracerOptions } from './types';
|
|
2
|
+
import {
|
|
3
|
+
NodeTracerProvider,
|
|
4
|
+
BatchSpanProcessor,
|
|
5
|
+
ConsoleSpanExporter,
|
|
6
|
+
SimpleSpanProcessor,
|
|
7
|
+
SpanExporter,
|
|
8
|
+
} from '@opentelemetry/sdk-trace-node';
|
|
9
|
+
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
|
|
10
|
+
|
|
11
|
+
import Instrumentations from './instrumentation';
|
|
12
|
+
import OpenlitConfig from './config';
|
|
13
|
+
|
|
14
|
+
export default class Tracing {
|
|
15
|
+
static traceProvider: NodeTracerProvider;
|
|
16
|
+
static traceExporter: OTLPTraceExporter;
|
|
17
|
+
static async setup(options: SetupTracerOptions) {
|
|
18
|
+
if (options.tracer) return options.tracer;
|
|
19
|
+
try {
|
|
20
|
+
this.traceProvider = new NodeTracerProvider({
|
|
21
|
+
resource: options.resource,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
OpenlitConfig.updateConfig({
|
|
25
|
+
...options,
|
|
26
|
+
tracer: options.tracer || Tracing.traceProvider,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
Instrumentations.setup(
|
|
30
|
+
Tracing.traceProvider,
|
|
31
|
+
options?.disabledInstrumentations,
|
|
32
|
+
options?.instrumentations
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
const consoleSpanExporter = new ConsoleSpanExporter();
|
|
36
|
+
|
|
37
|
+
// Adding span to console
|
|
38
|
+
this.traceProvider.addSpanProcessor(new SimpleSpanProcessor(consoleSpanExporter));
|
|
39
|
+
|
|
40
|
+
this.traceExporter = new OTLPTraceExporter({
|
|
41
|
+
url: options.otlpEndpoint,
|
|
42
|
+
headers: options.otlpHeaders as Record<string, unknown> | undefined,
|
|
43
|
+
});
|
|
44
|
+
if (options.disableBatch) {
|
|
45
|
+
this.traceProvider.addSpanProcessor(
|
|
46
|
+
new SimpleSpanProcessor(this.traceExporter as SpanExporter)
|
|
47
|
+
);
|
|
48
|
+
} else {
|
|
49
|
+
this.traceProvider.addSpanProcessor(
|
|
50
|
+
new BatchSpanProcessor(this.traceExporter as SpanExporter)
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
this.traceProvider.register();
|
|
55
|
+
} catch (e) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// import { Instrumentation } from '@opentelemetry/instrumentation';
|
|
2
|
+
import { Resource } from '@opentelemetry/resources';
|
|
3
|
+
import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
|
|
4
|
+
|
|
5
|
+
export type InstrumentationType = 'openai' | 'anthropic';
|
|
6
|
+
|
|
7
|
+
export type OpenlitInstrumentations = Partial<Record<InstrumentationType, any>>;
|
|
8
|
+
|
|
9
|
+
export type PricingObject = Record<string, Record<string, unknown>>;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* environment (string): Deployment environment of the application.
|
|
13
|
+
* applicationName (string): Name of the application using openLIT.
|
|
14
|
+
* pricingInfo (Object): Pricing information.
|
|
15
|
+
* tracer (any): Tracer instance for OpenTelemetry.
|
|
16
|
+
* otlpEndpoint (string): Endpoint for OTLP.
|
|
17
|
+
* otlpHeaders (Object): Headers for OTLP.
|
|
18
|
+
* disableBatch (boolean): Flag to disable batch span processing in tracing.
|
|
19
|
+
* traceContent (boolean): Flag to enable or disable tracing of content.
|
|
20
|
+
*/
|
|
21
|
+
export interface OpenlitConfigInterface {
|
|
22
|
+
environment?: string;
|
|
23
|
+
applicationName?: string;
|
|
24
|
+
pricingInfo?: PricingObject;
|
|
25
|
+
tracer: NodeTracerProvider;
|
|
26
|
+
otlpEndpoint?: string;
|
|
27
|
+
otlpHeaders?: Record<string, unknown>;
|
|
28
|
+
disableBatch?: boolean;
|
|
29
|
+
traceContent?: boolean;
|
|
30
|
+
pricing_json?: string | PricingObject;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type OpenlitOptions = {
|
|
34
|
+
environment?: OpenlitConfigInterface['environment'];
|
|
35
|
+
applicationName?: OpenlitConfigInterface['applicationName'];
|
|
36
|
+
tracer?: OpenlitConfigInterface['tracer'];
|
|
37
|
+
otlpEndpoint?: OpenlitConfigInterface['otlpEndpoint'];
|
|
38
|
+
otlpHeaders?: OpenlitConfigInterface['otlpHeaders'];
|
|
39
|
+
disableBatch?: OpenlitConfigInterface['disableBatch'];
|
|
40
|
+
traceContent?: OpenlitConfigInterface['traceContent'];
|
|
41
|
+
disabledInstrumentations?: string[];
|
|
42
|
+
instrumentations?: OpenlitInstrumentations;
|
|
43
|
+
pricing_json?: OpenlitConfigInterface['pricing_json'];
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export type SetupTracerOptions = OpenlitOptions & {
|
|
47
|
+
resource: Resource;
|
|
48
|
+
};
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es2016",
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"resolveJsonModule": true,
|
|
6
|
+
"outDir": "./dist",
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"forceConsistentCasingInFileNames": true,
|
|
9
|
+
"paths": {
|
|
10
|
+
"@/*": ["./src/*"]
|
|
11
|
+
},
|
|
12
|
+
"strict": true,
|
|
13
|
+
"skipLibCheck": true
|
|
14
|
+
}
|
|
15
|
+
}
|