@arizeai/phoenix-otel 0.0.1
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/README.md +31 -0
- package/dist/esm/config.d.ts +10 -0
- package/dist/esm/config.d.ts.map +1 -0
- package/dist/esm/config.js +19 -0
- package/dist/esm/config.js.map +1 -0
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/register.d.ts +39 -0
- package/dist/esm/register.d.ts.map +1 -0
- package/dist/esm/register.js +48 -0
- package/dist/esm/register.js.map +1 -0
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -0
- package/dist/src/config.d.ts +10 -0
- package/dist/src/config.d.ts.map +1 -0
- package/dist/src/config.js +23 -0
- package/dist/src/config.js.map +1 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +21 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/register.d.ts +39 -0
- package/dist/src/register.d.ts.map +1 -0
- package/dist/src/register.js +52 -0
- package/dist/src/register.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +51 -0
- package/src/config.ts +20 -0
- package/src/index.ts +2 -0
- package/src/register.ts +93 -0
package/src/register.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { SEMRESATTRS_PROJECT_NAME } from "@arizeai/openinference-semantic-conventions";
|
|
2
|
+
import {
|
|
3
|
+
OpenInferenceBatchSpanProcessor,
|
|
4
|
+
OpenInferenceSimpleSpanProcessor,
|
|
5
|
+
} from "@arizeai/openinference-vercel";
|
|
6
|
+
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto";
|
|
7
|
+
import { resourceFromAttributes } from "@opentelemetry/resources";
|
|
8
|
+
import {
|
|
9
|
+
NodeTracerProvider,
|
|
10
|
+
SpanProcessor,
|
|
11
|
+
} from "@opentelemetry/sdk-trace-node";
|
|
12
|
+
import { getEnvApiKey, getEnvCollectorURL } from "./config";
|
|
13
|
+
|
|
14
|
+
type RegisterParams = {
|
|
15
|
+
/**
|
|
16
|
+
* The project the spans should be associated to
|
|
17
|
+
* @default "default"
|
|
18
|
+
*/
|
|
19
|
+
projectName?: string;
|
|
20
|
+
/**
|
|
21
|
+
* the URL to the phoenix server. Can be postfixed with tracing path.
|
|
22
|
+
* If not provided, environment variables are checked.
|
|
23
|
+
* @example "https://app.phoenix.arize.com"
|
|
24
|
+
*/
|
|
25
|
+
url?: string;
|
|
26
|
+
/**
|
|
27
|
+
* The API key for the phoenix instance.
|
|
28
|
+
* If not provided, environment variables are checked.
|
|
29
|
+
*/
|
|
30
|
+
apiKey?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Whether to use batching for span processing.
|
|
33
|
+
* It is recommended to use batching in production environments
|
|
34
|
+
* @default true
|
|
35
|
+
*/
|
|
36
|
+
batch?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Whether to set the tracer as a global provider.
|
|
39
|
+
* @default true
|
|
40
|
+
*/
|
|
41
|
+
setGlobalTracerProvider?: boolean;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export function register({
|
|
45
|
+
url: paramsUrl,
|
|
46
|
+
apiKey: paramsApiKey,
|
|
47
|
+
projectName = "default",
|
|
48
|
+
batch = true,
|
|
49
|
+
setGlobalTracerProvider = true,
|
|
50
|
+
}: RegisterParams) {
|
|
51
|
+
const url = ensureCollectorEndpoint(
|
|
52
|
+
paramsUrl || getEnvCollectorURL() || "http://localhost:6006"
|
|
53
|
+
);
|
|
54
|
+
const apiKey = paramsApiKey || getEnvApiKey();
|
|
55
|
+
const headers: Record<string, string> = {};
|
|
56
|
+
const configureHeaders = typeof apiKey == "string";
|
|
57
|
+
if (configureHeaders) {
|
|
58
|
+
headers["authorization"] = `Bearer ${apiKey}`;
|
|
59
|
+
}
|
|
60
|
+
const exporter = new OTLPTraceExporter({
|
|
61
|
+
url,
|
|
62
|
+
headers,
|
|
63
|
+
});
|
|
64
|
+
let spanProcessor: SpanProcessor;
|
|
65
|
+
if (batch) {
|
|
66
|
+
spanProcessor = new OpenInferenceBatchSpanProcessor({ exporter });
|
|
67
|
+
} else {
|
|
68
|
+
spanProcessor = new OpenInferenceSimpleSpanProcessor({ exporter });
|
|
69
|
+
}
|
|
70
|
+
const provider = new NodeTracerProvider({
|
|
71
|
+
resource: resourceFromAttributes({
|
|
72
|
+
[SEMRESATTRS_PROJECT_NAME]: projectName,
|
|
73
|
+
}),
|
|
74
|
+
spanProcessors: [spanProcessor],
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
if (setGlobalTracerProvider) {
|
|
78
|
+
provider.register();
|
|
79
|
+
}
|
|
80
|
+
return provider;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* A utility method to normalize the url to be http compatible.
|
|
85
|
+
* Assumes we are using http over gRPC.
|
|
86
|
+
* @param url the url to the phoenix server. May contain a slug
|
|
87
|
+
*/
|
|
88
|
+
export function ensureCollectorEndpoint(url: string): string {
|
|
89
|
+
if (!url.includes("/v1/traces")) {
|
|
90
|
+
return new URL("/v1/traces", url).toString();
|
|
91
|
+
}
|
|
92
|
+
return new URL(url).toString();
|
|
93
|
+
}
|