@arizeai/phoenix-otel 0.0.1 → 0.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arizeai/phoenix-otel",
3
- "version": "0.0.1",
3
+ "version": "0.1.0",
4
4
  "description": "Otel registration and convenience methods",
5
5
  "main": "dist/src/index.js",
6
6
  "module": "dist/esm/index.js",
package/src/index.ts CHANGED
@@ -1,2 +1,4 @@
1
1
  export { trace } from "@opentelemetry/api";
2
- export * from "./register";
2
+ export { registerInstrumentations } from "@opentelemetry/instrumentation";
3
+ export { type RegisterParams, register } from "./register";
4
+ export { type Instrumentation } from "@opentelemetry/instrumentation";
package/src/register.ts CHANGED
@@ -10,15 +10,22 @@ import {
10
10
  SpanProcessor,
11
11
  } from "@opentelemetry/sdk-trace-node";
12
12
  import { getEnvApiKey, getEnvCollectorURL } from "./config";
13
+ import {
14
+ Instrumentation,
15
+ registerInstrumentations,
16
+ } from "@opentelemetry/instrumentation";
13
17
 
14
- type RegisterParams = {
18
+ /**
19
+ * Configuration parameters for registering Phoenix OpenTelemetry tracing
20
+ */
21
+ export type RegisterParams = {
15
22
  /**
16
23
  * The project the spans should be associated to
17
24
  * @default "default"
18
25
  */
19
26
  projectName?: string;
20
27
  /**
21
- * the URL to the phoenix server. Can be postfixed with tracing path.
28
+ * The URL to the phoenix server. Can be postfixed with tracing path.
22
29
  * If not provided, environment variables are checked.
23
30
  * @example "https://app.phoenix.arize.com"
24
31
  */
@@ -34,20 +41,50 @@ type RegisterParams = {
34
41
  * @default true
35
42
  */
36
43
  batch?: boolean;
44
+ /**
45
+ * A list of instrumentation to register.
46
+ * Note: this may only work with commonjs projects. ESM projects will require manually applying instrumentation.
47
+ */
48
+ instrumentations?: Instrumentation[];
37
49
  /**
38
50
  * Whether to set the tracer as a global provider.
39
51
  * @default true
40
52
  */
41
- setGlobalTracerProvider?: boolean;
53
+ global?: boolean;
42
54
  };
43
55
 
56
+ /**
57
+ * Registers Phoenix OpenTelemetry tracing with the specified configuration
58
+ *
59
+ * @param params - Configuration parameters for Phoenix tracing
60
+ * @param params.url - The URL to the phoenix server. Can be postfixed with tracing path
61
+ * @param params.apiKey - The API key for the phoenix instance
62
+ * @param params.projectName - The project the spans should be associated to
63
+ * @param params.instrumentations - A list of instrumentation to register
64
+ * @param params.batch - Whether to use batching for span processing
65
+ * @param params.global - Whether to set the tracer as a global provider
66
+ * @returns {NodeTracerProvider} The configured NodeTracerProvider instance
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * import { register } from '@arizeai/phoenix-otel';
71
+ *
72
+ * const provider = register({
73
+ * projectName: 'my-app',
74
+ * url: 'https://app.phoenix.arize.com',
75
+ * apiKey: 'your-api-key',
76
+ * batch: true
77
+ * });
78
+ * ```
79
+ */
44
80
  export function register({
45
81
  url: paramsUrl,
46
82
  apiKey: paramsApiKey,
47
83
  projectName = "default",
84
+ instrumentations,
48
85
  batch = true,
49
- setGlobalTracerProvider = true,
50
- }: RegisterParams) {
86
+ global = true,
87
+ }: RegisterParams): NodeTracerProvider {
51
88
  const url = ensureCollectorEndpoint(
52
89
  paramsUrl || getEnvCollectorURL() || "http://localhost:6006"
53
90
  );
@@ -74,16 +111,24 @@ export function register({
74
111
  spanProcessors: [spanProcessor],
75
112
  });
76
113
 
77
- if (setGlobalTracerProvider) {
114
+ if (instrumentations) {
115
+ registerInstrumentations({
116
+ instrumentations,
117
+ tracerProvider: provider,
118
+ });
119
+ }
120
+ if (global) {
78
121
  provider.register();
79
122
  }
80
123
  return provider;
81
124
  }
82
125
 
83
126
  /**
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
127
+ * A utility method to normalize the URL to be HTTP compatible.
128
+ * Assumes we are using HTTP over gRPC and ensures the URL ends with the correct traces endpoint.
129
+ *
130
+ * @param url - The URL to the phoenix server. May contain a slug
131
+ * @returns {string} The normalized URL with the '/v1/traces' endpoint
87
132
  */
88
133
  export function ensureCollectorEndpoint(url: string): string {
89
134
  if (!url.includes("/v1/traces")) {