-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstrumentation.ts
More file actions
42 lines (34 loc) · 1.46 KB
/
Copy pathinstrumentation.ts
File metadata and controls
42 lines (34 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { registerInstrumentations } from '@opentelemetry/instrumentation';
import {
NodeTracerProvider,
SimpleSpanProcessor,
} from '@opentelemetry/sdk-trace-node';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto';
import { ATTR_SERVICE_NAME } from '@opentelemetry/semantic-conventions';
import { diag, DiagConsoleLogger, DiagLogLevel } from '@opentelemetry/api';
import { LangChainInstrumentation } from '@arizeai/openinference-instrumentation-langchain';
import * as lcCallbackManager from '@langchain/core/callbacks/manager';
import { resourceFromAttributes } from '@opentelemetry/resources';
if (process.env.ENABLED_OPENINFERENCE_TELEMETRY === 'true') {
// For troubleshooting, set the log level to DiagLogLevel.DEBUG
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.DEBUG);
const provider = new NodeTracerProvider({
spanProcessors: [new SimpleSpanProcessor(
new OTLPTraceExporter({
url: process.env.COLLECTOR_ENDPOINT ?? 'http://localhost:6006/v1/traces',
}),
),
],
resource: resourceFromAttributes({
[ATTR_SERVICE_NAME]: 'chat-service',
}),
});
registerInstrumentations({
instrumentations: [],
});
// LangChain must be manually instrumented as it doesn't have a traditional module structure
const lcInstrumentation = new LangChainInstrumentation();
lcInstrumentation.manuallyInstrument(lcCallbackManager);
provider.register();
console.log('👀 OpenInference initialized');
}