@superblocksteam/sdk 2.0.83 → 2.0.84-next.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/.turbo/turbo-build.log +1 -1
- package/dist/cli-replacement/automatic-upgrades.d.ts +0 -6
- package/dist/cli-replacement/automatic-upgrades.d.ts.map +1 -1
- package/dist/cli-replacement/automatic-upgrades.js +5 -27
- package/dist/cli-replacement/automatic-upgrades.js.map +1 -1
- package/dist/cli-replacement/dev.d.mts.map +1 -1
- package/dist/cli-replacement/dev.mjs +260 -217
- package/dist/cli-replacement/dev.mjs.map +1 -1
- package/dist/cli-replacement/version-detection.d.ts +71 -0
- package/dist/cli-replacement/version-detection.d.ts.map +1 -0
- package/dist/cli-replacement/version-detection.js +186 -0
- package/dist/cli-replacement/version-detection.js.map +1 -0
- package/dist/cli-replacement/version-detection.test.d.ts +5 -0
- package/dist/cli-replacement/version-detection.test.d.ts.map +1 -0
- package/dist/cli-replacement/version-detection.test.js +257 -0
- package/dist/cli-replacement/version-detection.test.js.map +1 -0
- package/dist/dev-utils/dev-server.mjs +133 -115
- package/dist/dev-utils/dev-server.mjs.map +1 -1
- package/dist/telemetry/index.d.ts +4 -4
- package/dist/telemetry/index.d.ts.map +1 -1
- package/dist/telemetry/index.js +92 -64
- package/dist/telemetry/index.js.map +1 -1
- package/dist/telemetry/index.test.d.ts +2 -0
- package/dist/telemetry/index.test.d.ts.map +1 -0
- package/dist/telemetry/index.test.js +93 -0
- package/dist/telemetry/index.test.js.map +1 -0
- package/dist/telemetry/local-obs.d.ts +73 -0
- package/dist/telemetry/local-obs.d.ts.map +1 -0
- package/dist/telemetry/local-obs.js +107 -0
- package/dist/telemetry/local-obs.js.map +1 -0
- package/dist/telemetry/util.d.ts +1 -2
- package/dist/telemetry/util.d.ts.map +1 -1
- package/dist/telemetry/util.js +26 -4
- package/dist/telemetry/util.js.map +1 -1
- package/package.json +6 -5
- package/src/cli-replacement/automatic-upgrades.ts +10 -42
- package/src/cli-replacement/dev.mts +336 -281
- package/src/cli-replacement/version-detection.test.ts +336 -0
- package/src/cli-replacement/version-detection.ts +220 -0
- package/src/dev-utils/dev-server.mts +149 -127
- package/src/telemetry/index.test.ts +130 -0
- package/src/telemetry/index.ts +105 -83
- package/src/telemetry/local-obs.ts +138 -0
- package/src/telemetry/util.ts +27 -4
- package/tsconfig.tsbuildinfo +1 -1
- package/turbo.json +20 -2
package/src/telemetry/index.ts
CHANGED
|
@@ -1,16 +1,8 @@
|
|
|
1
1
|
import os from "node:os";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-http";
|
|
5
|
-
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
|
|
2
|
+
import { trace, type Tracer } from "@opentelemetry/api";
|
|
3
|
+
import { logs, type Logger } from "@opentelemetry/api-logs";
|
|
6
4
|
import { ExpressInstrumentation } from "@opentelemetry/instrumentation-express";
|
|
7
5
|
import { HttpInstrumentation } from "@opentelemetry/instrumentation-http";
|
|
8
|
-
import { Resource } from "@opentelemetry/resources";
|
|
9
|
-
import { NodeSDK, logs, api } from "@opentelemetry/sdk-node";
|
|
10
|
-
import {
|
|
11
|
-
ATTR_SERVICE_NAME,
|
|
12
|
-
ATTR_SERVICE_VERSION,
|
|
13
|
-
} from "@opentelemetry/semantic-conventions";
|
|
14
6
|
import {
|
|
15
7
|
DeploymentTypeEnum,
|
|
16
8
|
OBS_TAG_APPLICATION_ID,
|
|
@@ -18,10 +10,18 @@ import {
|
|
|
18
10
|
OBS_TAG_ORG_ID,
|
|
19
11
|
OBS_TAG_USER_EMAIL,
|
|
20
12
|
} from "@superblocksteam/shared";
|
|
13
|
+
import {
|
|
14
|
+
initNodeTelemetry,
|
|
15
|
+
getTelemetryInstance,
|
|
16
|
+
isTelemetryInitialized,
|
|
17
|
+
parseDeploymentType,
|
|
18
|
+
resetTelemetry,
|
|
19
|
+
getDefaultPolicy,
|
|
20
|
+
} from "@superblocksteam/telemetry";
|
|
21
|
+
// Note: dd-trace kept for LLMObs until Epic 07 completes
|
|
21
22
|
import ddTrace from "dd-trace";
|
|
22
23
|
import packageJson from "../../package.json" with { type: "json" };
|
|
23
24
|
import {
|
|
24
|
-
ATTR_DEPLOYMENT_ENVIRONMENT,
|
|
25
25
|
ATTR_SUPERBLOCKS_BASE_URL,
|
|
26
26
|
ATTR_SUPERBLOCKS_CLI_TOKEN,
|
|
27
27
|
ATTR_SUPERBLOCKS_CSB_ID,
|
|
@@ -29,44 +29,34 @@ import {
|
|
|
29
29
|
ATTR_SUPERBLOCKS_USER_ID,
|
|
30
30
|
getEnvironmentFromHostname,
|
|
31
31
|
} from "./attributes.js";
|
|
32
|
+
import { applyLocalObsEnvVars, isLocalObsEnabled } from "./local-obs.js";
|
|
32
33
|
import { getLogger as getStandardLogger } from "./logging.js";
|
|
33
34
|
import { getConfiguration, SERVICE_NAME } from "./util.js";
|
|
34
35
|
import type { ApplicationConfigWithTokenConfigAndUserInfo } from "../types/index.js";
|
|
35
|
-
import type { Tracer } from "@opentelemetry/api";
|
|
36
|
-
import type { Logger } from "@opentelemetry/api-logs";
|
|
37
36
|
|
|
38
|
-
|
|
37
|
+
// Apply local observability env vars early, before dd-trace auto-init
|
|
38
|
+
applyLocalObsEnvVars();
|
|
39
|
+
|
|
40
|
+
// Configuration state
|
|
41
|
+
let config: Awaited<ReturnType<typeof getConfiguration>> | undefined =
|
|
42
|
+
undefined;
|
|
39
43
|
let configured = false;
|
|
40
|
-
let sdkInstance: NodeSDK | undefined = undefined;
|
|
41
44
|
|
|
42
45
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
46
|
+
* Current deployment type based on SUPERBLOCKS_DEPLOYMENT_TYPE env var.
|
|
47
|
+
* Defaults to CLOUD if not specified or invalid.
|
|
45
48
|
*/
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return
|
|
49
|
-
}
|
|
50
|
-
if (
|
|
51
|
-
!Object.values(DeploymentTypeEnum).includes(value as DeploymentTypeEnum)
|
|
52
|
-
) {
|
|
49
|
+
export const deploymentType = (() => {
|
|
50
|
+
try {
|
|
51
|
+
return parseDeploymentType(process.env.SUPERBLOCKS_DEPLOYMENT_TYPE);
|
|
52
|
+
} catch (error) {
|
|
53
53
|
console.warn(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
`Defaulting to "${DeploymentTypeEnum.CLOUD}".`,
|
|
54
|
+
"[Telemetry] Invalid SUPERBLOCKS_DEPLOYMENT_TYPE, defaulting to CLOUD:",
|
|
55
|
+
error,
|
|
57
56
|
);
|
|
58
57
|
return DeploymentTypeEnum.CLOUD;
|
|
59
58
|
}
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Current deployment type based on SUPERBLOCKS_DEPLOYMENT_TYPE env var.
|
|
65
|
-
* Defaults to CLOUD if not specified. Throws if an invalid value is provided.
|
|
66
|
-
*/
|
|
67
|
-
export const deploymentType = getValidDeploymentType(
|
|
68
|
-
process.env.SUPERBLOCKS_DEPLOYMENT_TYPE,
|
|
69
|
-
);
|
|
59
|
+
})();
|
|
70
60
|
|
|
71
61
|
/**
|
|
72
62
|
* Whether the current deployment is CLOUD_PREM.
|
|
@@ -77,16 +67,21 @@ export const deploymentType = getValidDeploymentType(
|
|
|
77
67
|
export const isCloudPrem = deploymentType === DeploymentTypeEnum.CLOUD_PREM;
|
|
78
68
|
|
|
79
69
|
async function shutdownTelemetry(): Promise<void> {
|
|
80
|
-
if (
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
70
|
+
if (isTelemetryInitialized()) {
|
|
71
|
+
try {
|
|
72
|
+
await getTelemetryInstance().shutdown();
|
|
73
|
+
} catch (error) {
|
|
74
|
+
console.error("Error during telemetry shutdown:", error);
|
|
75
|
+
} finally {
|
|
76
|
+
resetTelemetry();
|
|
77
|
+
configured = false;
|
|
78
|
+
}
|
|
84
79
|
}
|
|
85
80
|
}
|
|
86
81
|
|
|
87
82
|
export async function configureTelemetry(
|
|
88
83
|
applicationConfig?: ApplicationConfigWithTokenConfigAndUserInfo,
|
|
89
|
-
) {
|
|
84
|
+
): Promise<boolean> {
|
|
90
85
|
const logger = getStandardLogger();
|
|
91
86
|
if (configured) {
|
|
92
87
|
await shutdownTelemetry();
|
|
@@ -99,21 +94,28 @@ export async function configureTelemetry(
|
|
|
99
94
|
} catch (error) {
|
|
100
95
|
console.error(error);
|
|
101
96
|
configured = false;
|
|
102
|
-
return;
|
|
97
|
+
return false;
|
|
103
98
|
}
|
|
104
99
|
|
|
105
100
|
logger.info(
|
|
106
101
|
`[INIT] Initializing telemetry for service ${config.serviceName} at Superblocks instance ${config.superblocksHostname}`,
|
|
107
102
|
);
|
|
108
103
|
|
|
104
|
+
// Check for local observability mode (SUPERBLOCKS_LOCAL_OBS=true)
|
|
105
|
+
const isLocalObs = isLocalObsEnabled();
|
|
106
|
+
|
|
107
|
+
// Allow env var override for local development testing (AGENT-1048)
|
|
108
|
+
// Local obs mode always enables LLMObs
|
|
109
109
|
const llmobsEnabled =
|
|
110
|
-
|
|
110
|
+
isLocalObs ||
|
|
111
|
+
process.env.SUPERBLOCKS_LLMOBS_ENABLED === "true" ||
|
|
112
|
+
(applicationConfig?.featureFlags.devServerLlmobsEnabled() ?? false);
|
|
111
113
|
|
|
112
114
|
logger.debug(
|
|
113
|
-
`[INIT] superblocks.dev-server.llmobs.enabled=${llmobsEnabled} for service ${config.serviceName}`,
|
|
115
|
+
`[INIT] superblocks.dev-server.llmobs.enabled=${llmobsEnabled} (localObs=${isLocalObs}) for service ${config.serviceName}`,
|
|
114
116
|
);
|
|
115
117
|
|
|
116
|
-
// Configure dd-trace for
|
|
118
|
+
// Configure dd-trace for LLMObs (migrated to OTEL in Epic 07)
|
|
117
119
|
process.env.DD_SITE = "datadoghq.com";
|
|
118
120
|
// stop ddTrace from trying to get remote configuration
|
|
119
121
|
process.env.DD_REMOTE_CONFIGURATION_ENABLED = "false";
|
|
@@ -149,48 +151,68 @@ export async function configureTelemetry(
|
|
|
149
151
|
} for service ${config.serviceName}`,
|
|
150
152
|
);
|
|
151
153
|
|
|
152
|
-
// Configure OpenTelemetry for APM traces and logs
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
),
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
154
|
+
// Configure OpenTelemetry for APM traces and logs via shared telemetry package
|
|
155
|
+
const policy = getDefaultPolicy(deploymentType);
|
|
156
|
+
|
|
157
|
+
try {
|
|
158
|
+
initNodeTelemetry(
|
|
159
|
+
{
|
|
160
|
+
serviceName: config.serviceName,
|
|
161
|
+
serviceVersion: packageJson.version,
|
|
162
|
+
environment: getEnvironmentFromHostname(config.superblocksHostname),
|
|
163
|
+
otlpUrl: config.otlpBaseUrl,
|
|
164
|
+
resourceAttributes: {
|
|
165
|
+
[ATTR_SUPERBLOCKS_BASE_URL]: config.superblocksHostname,
|
|
166
|
+
[ATTR_SUPERBLOCKS_CLI_TOKEN]: config.token,
|
|
167
|
+
[ATTR_SUPERBLOCKS_IS_CSB]: String(!!process.env.SUPERBLOCKS_IS_CSB),
|
|
168
|
+
...(process.env.SUPERBLOCKS_IS_CSB && {
|
|
169
|
+
[ATTR_SUPERBLOCKS_CSB_ID]: os.hostname(),
|
|
170
|
+
}),
|
|
171
|
+
...(applicationConfig?.id && {
|
|
172
|
+
[OBS_TAG_APPLICATION_ID]: applicationConfig.id,
|
|
173
|
+
}),
|
|
174
|
+
...(applicationConfig?.branchName && {
|
|
175
|
+
[OBS_TAG_BRANCH]: applicationConfig.branchName,
|
|
176
|
+
}),
|
|
177
|
+
...(applicationConfig?.userEmail && {
|
|
178
|
+
[OBS_TAG_USER_EMAIL]: applicationConfig.userEmail,
|
|
179
|
+
}),
|
|
180
|
+
...(applicationConfig?.userId && {
|
|
181
|
+
[ATTR_SUPERBLOCKS_USER_ID]: applicationConfig.userId,
|
|
182
|
+
}),
|
|
183
|
+
...(applicationConfig?.organizationId && {
|
|
184
|
+
[OBS_TAG_ORG_ID]: applicationConfig.organizationId,
|
|
185
|
+
}),
|
|
186
|
+
},
|
|
187
|
+
instrumentations: [
|
|
188
|
+
new HttpInstrumentation(),
|
|
189
|
+
new ExpressInstrumentation(),
|
|
190
|
+
],
|
|
191
|
+
logsEnabled: true,
|
|
192
|
+
},
|
|
193
|
+
policy,
|
|
194
|
+
);
|
|
195
|
+
} catch (error) {
|
|
196
|
+
console.error("[Telemetry] Failed to initialize OpenTelemetry:", error);
|
|
197
|
+
configured = false;
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
186
200
|
|
|
187
|
-
|
|
201
|
+
return true;
|
|
188
202
|
}
|
|
189
203
|
|
|
190
204
|
export function getLogger(): Logger {
|
|
191
|
-
|
|
205
|
+
if (isTelemetryInitialized()) {
|
|
206
|
+
return getTelemetryInstance().getLogger(SERVICE_NAME);
|
|
207
|
+
}
|
|
208
|
+
// Fallback to global API if telemetry not initialized
|
|
209
|
+
return logs.getLogger(SERVICE_NAME, packageJson.version);
|
|
192
210
|
}
|
|
193
211
|
|
|
194
212
|
export function getTracer(): Tracer {
|
|
195
|
-
|
|
213
|
+
if (isTelemetryInitialized()) {
|
|
214
|
+
return getTelemetryInstance().getTracer(SERVICE_NAME);
|
|
215
|
+
}
|
|
216
|
+
// Fallback to global API if telemetry not initialized
|
|
217
|
+
return trace.getTracer(SERVICE_NAME, packageJson.version);
|
|
196
218
|
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local Observability Configuration
|
|
3
|
+
*
|
|
4
|
+
* Provides a single toggle (SUPERBLOCKS_LOCAL_OBS=true) that auto-configures
|
|
5
|
+
* all environment variables needed for local observability testing with the
|
|
6
|
+
* LGTM stack (Loki, Grafana, Tempo, Mimir).
|
|
7
|
+
*
|
|
8
|
+
* This eliminates the need to manually set 9+ environment variables:
|
|
9
|
+
* - SUPERBLOCKS_DEPLOYMENT_TYPE
|
|
10
|
+
* - SUPERBLOCKS_LLMOBS_ENABLED
|
|
11
|
+
* - OTEL_EXPORTER_OTLP_ENDPOINT
|
|
12
|
+
* - SUPERBLOCKS_OTEL_COLLECTOR_URL
|
|
13
|
+
* - DD_LLMOBS_ENABLED
|
|
14
|
+
* - DD_LLMOBS_ML_APP
|
|
15
|
+
* - DD_LLMOBS_AGENTLESS_ENABLED
|
|
16
|
+
* - DD_SITE
|
|
17
|
+
* - DD_API_KEY
|
|
18
|
+
*
|
|
19
|
+
* Usage:
|
|
20
|
+
* SUPERBLOCKS_LOCAL_OBS=true pnpm start:all
|
|
21
|
+
*
|
|
22
|
+
* Or with custom OTEL endpoint:
|
|
23
|
+
* SUPERBLOCKS_LOCAL_OBS=true OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318 pnpm start:all
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import { DeploymentTypeEnum } from "@superblocksteam/shared";
|
|
27
|
+
|
|
28
|
+
const DEFAULT_LOCAL_OTEL_ENDPOINT = "http://localhost:24318";
|
|
29
|
+
const DEFAULT_ML_APP_NAME = "superblocks-ai-code-gen";
|
|
30
|
+
|
|
31
|
+
export interface LocalObsConfig {
|
|
32
|
+
/** Whether local observability mode is enabled */
|
|
33
|
+
enabled: boolean;
|
|
34
|
+
/** OTEL endpoint for traces, metrics, logs */
|
|
35
|
+
otelEndpoint: string;
|
|
36
|
+
/** Deployment type (cloud-prem for local obs) */
|
|
37
|
+
deploymentType: DeploymentTypeEnum.CLOUD_PREM;
|
|
38
|
+
/** LLMObs configuration */
|
|
39
|
+
llmobs: {
|
|
40
|
+
enabled: true;
|
|
41
|
+
mlApp: string;
|
|
42
|
+
agentlessEnabled: true;
|
|
43
|
+
};
|
|
44
|
+
/** Datadog configuration for dd-trace */
|
|
45
|
+
datadog: {
|
|
46
|
+
site: string;
|
|
47
|
+
apiKey: string;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Checks if local observability mode is enabled.
|
|
53
|
+
*
|
|
54
|
+
* Returns true if:
|
|
55
|
+
* - SUPERBLOCKS_LOCAL_OBS=true (primary toggle)
|
|
56
|
+
* - OR all required env vars are manually configured (legacy mode)
|
|
57
|
+
*/
|
|
58
|
+
export function isLocalObsEnabled(): boolean {
|
|
59
|
+
// Primary toggle
|
|
60
|
+
if (process.env.SUPERBLOCKS_LOCAL_OBS === "true") {
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Legacy mode: all env vars manually configured
|
|
65
|
+
const hasLegacyConfig =
|
|
66
|
+
process.env.SUPERBLOCKS_DEPLOYMENT_TYPE === DeploymentTypeEnum.CLOUD_PREM &&
|
|
67
|
+
process.env.SUPERBLOCKS_LLMOBS_ENABLED === "true" &&
|
|
68
|
+
!!process.env.OTEL_EXPORTER_OTLP_ENDPOINT;
|
|
69
|
+
|
|
70
|
+
return hasLegacyConfig;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Gets the local observability configuration.
|
|
75
|
+
*
|
|
76
|
+
* When SUPERBLOCKS_LOCAL_OBS=true, this returns a complete configuration
|
|
77
|
+
* with sensible defaults for local development. Individual values can still
|
|
78
|
+
* be overridden via environment variables.
|
|
79
|
+
*
|
|
80
|
+
* @returns LocalObsConfig if local obs is enabled, null otherwise
|
|
81
|
+
*/
|
|
82
|
+
export function getLocalObsConfig(): LocalObsConfig | null {
|
|
83
|
+
if (!isLocalObsEnabled()) {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return {
|
|
88
|
+
enabled: true,
|
|
89
|
+
otelEndpoint:
|
|
90
|
+
process.env.OTEL_EXPORTER_OTLP_ENDPOINT || DEFAULT_LOCAL_OTEL_ENDPOINT,
|
|
91
|
+
deploymentType: DeploymentTypeEnum.CLOUD_PREM,
|
|
92
|
+
llmobs: {
|
|
93
|
+
enabled: true,
|
|
94
|
+
mlApp: process.env.DD_LLMOBS_ML_APP || DEFAULT_ML_APP_NAME,
|
|
95
|
+
agentlessEnabled: true,
|
|
96
|
+
},
|
|
97
|
+
datadog: {
|
|
98
|
+
site: process.env.DD_SITE || "datadoghq.com",
|
|
99
|
+
// Dummy key for agentless mode - not used when exporting to local OTEL
|
|
100
|
+
apiKey: process.env.DD_API_KEY || "local-dev-dummy-key",
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Applies local observability configuration to process.env.
|
|
107
|
+
*
|
|
108
|
+
* This ensures that all downstream code that reads env vars directly
|
|
109
|
+
* (like dd-trace auto-initialization) gets the correct values.
|
|
110
|
+
*
|
|
111
|
+
* Should be called early in the application lifecycle, before any
|
|
112
|
+
* telemetry initialization occurs.
|
|
113
|
+
*/
|
|
114
|
+
export function applyLocalObsEnvVars(): void {
|
|
115
|
+
const config = getLocalObsConfig();
|
|
116
|
+
if (!config) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Apply env vars if not already set (allow explicit overrides)
|
|
121
|
+
const envDefaults: Record<string, string> = {
|
|
122
|
+
SUPERBLOCKS_DEPLOYMENT_TYPE: config.deploymentType,
|
|
123
|
+
SUPERBLOCKS_LLMOBS_ENABLED: "true",
|
|
124
|
+
OTEL_EXPORTER_OTLP_ENDPOINT: config.otelEndpoint,
|
|
125
|
+
SUPERBLOCKS_OTEL_COLLECTOR_URL: config.otelEndpoint,
|
|
126
|
+
DD_LLMOBS_ENABLED: "1",
|
|
127
|
+
DD_LLMOBS_ML_APP: config.llmobs.mlApp,
|
|
128
|
+
DD_LLMOBS_AGENTLESS_ENABLED: "1",
|
|
129
|
+
DD_SITE: config.datadog.site,
|
|
130
|
+
DD_API_KEY: config.datadog.apiKey,
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
for (const [key, value] of Object.entries(envDefaults)) {
|
|
134
|
+
if (!process.env[key]) {
|
|
135
|
+
process.env[key] = value;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
package/src/telemetry/util.ts
CHANGED
|
@@ -2,12 +2,36 @@ import { getLocalTokenWithUrl } from "@superblocksteam/util";
|
|
|
2
2
|
|
|
3
3
|
export const SERVICE_NAME = "sdk-dev-server";
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Get the OTLP base URL for telemetry export.
|
|
7
|
+
*
|
|
8
|
+
* Priority:
|
|
9
|
+
* 1. SUPERBLOCKS_OTEL_COLLECTOR_URL env var (for local obs mode)
|
|
10
|
+
* 2. Superblocks API endpoint derived from base URL
|
|
11
|
+
*
|
|
12
|
+
* When SUPERBLOCKS_OTEL_COLLECTOR_URL is set (e.g., http://localhost:24318),
|
|
13
|
+
* telemetry is sent directly to the local OTEL collector.
|
|
14
|
+
*
|
|
15
|
+
* Note: This returns the BASE URL. The telemetry library appends /v1/traces,
|
|
16
|
+
* /v1/metrics, /v1/logs to this URL.
|
|
17
|
+
*/
|
|
18
|
+
function getOtlpBaseUrl(superblocksBaseUrl: URL): string {
|
|
19
|
+
const localOtelUrl = process.env.SUPERBLOCKS_OTEL_COLLECTOR_URL;
|
|
20
|
+
if (localOtelUrl) {
|
|
21
|
+
// Remove trailing /v1/traces etc. if present (just use base URL)
|
|
22
|
+
return localOtelUrl.replace(/\/v1\/(traces|metrics|logs)$/, "");
|
|
23
|
+
}
|
|
24
|
+
// Default: Superblocks API proxies OTLP requests
|
|
25
|
+
// The server expects /api/v1/traces but the telemetry lib adds /v1/traces,
|
|
26
|
+
// so we return /api and let telemetry lib append /v1/traces
|
|
27
|
+
return superblocksBaseUrl.origin + "/api";
|
|
28
|
+
}
|
|
29
|
+
|
|
5
30
|
export async function getConfiguration() {
|
|
6
31
|
try {
|
|
7
32
|
const tokenWithUrl = await getLocalTokenWithUrl();
|
|
8
33
|
const superblocksBaseUrl = new URL(tokenWithUrl.superblocksBaseUrl);
|
|
9
|
-
const
|
|
10
|
-
const superblocksLogsUrl = superblocksBaseUrl.origin + "/api/v1/logs";
|
|
34
|
+
const otlpBaseUrl = getOtlpBaseUrl(superblocksBaseUrl);
|
|
11
35
|
const superblocksHostname = superblocksBaseUrl.hostname;
|
|
12
36
|
let token = "";
|
|
13
37
|
if ("token" in tokenWithUrl) {
|
|
@@ -15,8 +39,7 @@ export async function getConfiguration() {
|
|
|
15
39
|
}
|
|
16
40
|
return {
|
|
17
41
|
superblocksBaseUrl,
|
|
18
|
-
|
|
19
|
-
superblocksLogsUrl,
|
|
42
|
+
otlpBaseUrl,
|
|
20
43
|
superblocksHostname,
|
|
21
44
|
serviceName: SERVICE_NAME,
|
|
22
45
|
token,
|