autotel-backends 2.11.4 → 2.12.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.
@@ -0,0 +1,86 @@
1
+ import { AutotelConfig } from 'autotel';
2
+ import { LogRecordProcessor } from '@opentelemetry/sdk-logs';
3
+
4
+ /**
5
+ * Grafana Cloud preset for autotel
6
+ *
7
+ * Provides a simplified configuration helper for sending traces, metrics,
8
+ * and logs to Grafana Cloud via the OTLP gateway.
9
+ *
10
+ * Get your endpoint and headers from:
11
+ * Grafana Cloud Portal → your stack → Connections → OpenTelemetry → Configure
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * import { init } from 'autotel';
16
+ * import { createGrafanaConfig } from 'autotel-backends/grafana';
17
+ *
18
+ * init(createGrafanaConfig({
19
+ * endpoint: process.env.OTEL_EXPORTER_OTLP_ENDPOINT!,
20
+ * headers: process.env.OTEL_EXPORTER_OTLP_HEADERS,
21
+ * service: 'my-app',
22
+ * enableLogs: true,
23
+ * }));
24
+ * ```
25
+ */
26
+
27
+ /**
28
+ * Configuration options for Grafana Cloud preset
29
+ */
30
+ interface GrafanaPresetConfig {
31
+ /**
32
+ * OTLP gateway endpoint (required).
33
+ * From Grafana Cloud: Stack → Connections → OpenTelemetry → Configure.
34
+ * Example: https://otlp-gateway-prod-gb-south-1.grafana.net/otlp
35
+ */
36
+ endpoint: string;
37
+ /**
38
+ * OTLP authentication headers.
39
+ * From the same Configure tile; usually Basic auth.
40
+ * Example: "Authorization=Basic%20BASE64_INSTANCE_ID_AND_TOKEN"
41
+ * or object: { Authorization: 'Basic ...' }
42
+ */
43
+ headers?: string | Record<string, string>;
44
+ /**
45
+ * Service name (required).
46
+ * Appears in Tempo, Mimir, and Loki as service_name.
47
+ */
48
+ service: string;
49
+ /**
50
+ * Deployment environment (e.g. 'production', 'staging').
51
+ *
52
+ * @default process.env.NODE_ENV || 'development'
53
+ */
54
+ environment?: string;
55
+ /**
56
+ * Service version for deployment tracking.
57
+ *
58
+ * @default process.env.OTEL_SERVICE_VERSION
59
+ */
60
+ version?: string;
61
+ /**
62
+ * Enable log export to Grafana Cloud (Loki) via OTLP.
63
+ * When true, configures logRecordProcessors so OTel Logs API records are exported.
64
+ *
65
+ * @default true
66
+ */
67
+ enableLogs?: boolean;
68
+ /**
69
+ * Custom log record processors (advanced).
70
+ * Overrides the default OTLP log processor when enableLogs is true.
71
+ */
72
+ logRecordProcessors?: LogRecordProcessor[];
73
+ }
74
+ /**
75
+ * Create an autotel configuration for Grafana Cloud OTLP.
76
+ *
77
+ * Sends traces (Tempo), metrics (Mimir), and optionally logs (Loki) to the
78
+ * Grafana Cloud OTLP gateway. Endpoint and headers come from the stack's
79
+ * Connections → OpenTelemetry → Configure tile.
80
+ *
81
+ * @param config - Grafana Cloud configuration options
82
+ * @returns AutotelConfig ready to pass to init()
83
+ */
84
+ declare function createGrafanaConfig(config: GrafanaPresetConfig): AutotelConfig;
85
+
86
+ export { type GrafanaPresetConfig, createGrafanaConfig };
@@ -0,0 +1,41 @@
1
+ 'use strict';
2
+
3
+ // src/honeycomb.ts
4
+ function createHoneycombConfig(config) {
5
+ const {
6
+ apiKey,
7
+ service,
8
+ dataset,
9
+ environment,
10
+ version,
11
+ endpoint = "api.honeycomb.io:443",
12
+ sampleRate
13
+ } = config;
14
+ if (!apiKey) {
15
+ throw new Error(
16
+ "Honeycomb API key is required. Get your API key from: https://ui.honeycomb.io/account"
17
+ );
18
+ }
19
+ const headers = {
20
+ "x-honeycomb-team": apiKey
21
+ };
22
+ if (dataset) {
23
+ headers["x-honeycomb-dataset"] = dataset;
24
+ }
25
+ if (sampleRate !== void 0) {
26
+ headers["x-honeycomb-samplerate"] = String(sampleRate);
27
+ }
28
+ return {
29
+ service,
30
+ environment,
31
+ version,
32
+ protocol: "grpc",
33
+ // Honeycomb uses gRPC for better performance
34
+ endpoint,
35
+ headers
36
+ };
37
+ }
38
+
39
+ exports.createHoneycombConfig = createHoneycombConfig;
40
+ //# sourceMappingURL=honeycomb.cjs.map
41
+ //# sourceMappingURL=honeycomb.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/honeycomb.ts"],"names":[],"mappings":";;;AA4IO,SAAS,sBACd,MAAA,EACe;AACf,EAAA,MAAM;AAAA,IACJ,MAAA;AAAA,IACA,OAAA;AAAA,IACA,OAAA;AAAA,IACA,WAAA;AAAA,IACA,OAAA;AAAA,IACA,QAAA,GAAW,sBAAA;AAAA,IACX;AAAA,GACF,GAAI,MAAA;AAGJ,EAAA,IAAI,CAAC,MAAA,EAAQ;AACX,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KACF;AAAA,EACF;AAGA,EAAA,MAAM,OAAA,GAAkC;AAAA,IACtC,kBAAA,EAAoB;AAAA,GACtB;AAGA,EAAA,IAAI,OAAA,EAAS;AACX,IAAA,OAAA,CAAQ,qBAAqB,CAAA,GAAI,OAAA;AAAA,EACnC;AAGA,EAAA,IAAI,eAAe,MAAA,EAAW;AAC5B,IAAA,OAAA,CAAQ,wBAAwB,CAAA,GAAI,MAAA,CAAO,UAAU,CAAA;AAAA,EACvD;AAEA,EAAA,OAAO;AAAA,IACL,OAAA;AAAA,IACA,WAAA;AAAA,IACA,OAAA;AAAA,IACA,QAAA,EAAU,MAAA;AAAA;AAAA,IACV,QAAA;AAAA,IACA;AAAA,GACF;AACF","file":"honeycomb.cjs","sourcesContent":["/**\n * Honeycomb preset for autotel\n *\n * Provides a simplified configuration helper for Honeycomb integration\n * with best practices built-in.\n *\n * @example Using Honeycomb with API key\n * ```typescript\n * import { init } from 'autotel';\n * import { createHoneycombConfig } from 'autotel-backends/honeycomb';\n *\n * init(createHoneycombConfig({\n * apiKey: process.env.HONEYCOMB_API_KEY!,\n * service: 'my-app',\n * }));\n * ```\n *\n * @example With custom dataset\n * ```typescript\n * import { init } from 'autotel';\n * import { createHoneycombConfig } from 'autotel-backends/honeycomb';\n *\n * init(createHoneycombConfig({\n * apiKey: process.env.HONEYCOMB_API_KEY!,\n * service: 'my-app',\n * dataset: 'production',\n * }));\n * ```\n */\n\nimport type { AutotelConfig } from 'autotel';\n\n/**\n * Configuration options for Honeycomb preset\n */\nexport interface HoneycombPresetConfig {\n /**\n * Honeycomb API key (required).\n *\n * Get your API key from:\n * https://ui.honeycomb.io/account\n *\n * For classic environments, use an environment-specific key.\n * For newer environments, use a team-level API key.\n */\n apiKey: string;\n\n /**\n * Service name (required).\n * Appears as service.name in Honeycomb traces and determines dataset routing.\n */\n service: string;\n\n /**\n * Dataset name (optional).\n * For classic Honeycomb accounts that use datasets.\n * Modern environments route based on service.name instead.\n *\n * @default service name\n */\n dataset?: string;\n\n /**\n * Deployment environment (e.g., 'production', 'staging', 'development').\n * Used for environment filtering in Honeycomb.\n *\n * @default process.env.NODE_ENV || 'development'\n */\n environment?: string;\n\n /**\n * Service version for deployment tracking.\n *\n * @default process.env.VERSION || auto-detected from package.json\n */\n version?: string;\n\n /**\n * Honeycomb API endpoint.\n * Use this to configure for different regions or on-premises installations.\n *\n * @default 'api.honeycomb.io:443'\n */\n endpoint?: string;\n\n /**\n * Sample rate for traces (1 = 100%, 10 = 10%, 100 = 1%).\n * Honeycomb's head-based sampling rate.\n *\n * Note: Autotel uses tail-based sampling by default.\n * This setting applies additional head-based sampling if specified.\n *\n * @default undefined (no head-based sampling, relies on tail sampling)\n */\n sampleRate?: number;\n}\n\n/**\n * Create an autotel configuration optimized for Honeycomb.\n *\n * This preset handles:\n * - gRPC protocol configuration (Honeycomb's preferred protocol)\n * - Proper endpoint and authentication headers\n * - Dataset routing (for classic accounts)\n * - Unified service tagging (service, env, version)\n *\n * Honeycomb uses gRPC by default for better performance and lower overhead.\n * This preset automatically configures the gRPC protocol.\n *\n * @param config - Honeycomb-specific configuration options\n * @returns AutotelConfig ready to pass to init()\n *\n * @example Simple configuration\n * ```typescript\n * init(createHoneycombConfig({\n * apiKey: process.env.HONEYCOMB_API_KEY!,\n * service: 'my-app',\n * }));\n * ```\n *\n * @example With custom dataset and environment\n * ```typescript\n * init(createHoneycombConfig({\n * apiKey: process.env.HONEYCOMB_API_KEY!,\n * service: 'my-app',\n * dataset: 'production',\n * environment: 'production',\n * version: '2.1.0',\n * }));\n * ```\n *\n * @example With sample rate\n * ```typescript\n * init(createHoneycombConfig({\n * apiKey: process.env.HONEYCOMB_API_KEY!,\n * service: 'my-app',\n * sampleRate: 10, // Sample 10% of traces (head-based sampling)\n * }));\n * ```\n */\nexport function createHoneycombConfig(\n config: HoneycombPresetConfig,\n): AutotelConfig {\n const {\n apiKey,\n service,\n dataset,\n environment,\n version,\n endpoint = 'api.honeycomb.io:443',\n sampleRate,\n } = config;\n\n // Validation: API key is required\n if (!apiKey) {\n throw new Error(\n 'Honeycomb API key is required. Get your API key from: https://ui.honeycomb.io/account',\n );\n }\n\n // Build headers\n const headers: Record<string, string> = {\n 'x-honeycomb-team': apiKey,\n };\n\n // Add dataset header if specified (for classic Honeycomb accounts)\n if (dataset) {\n headers['x-honeycomb-dataset'] = dataset;\n }\n\n // Add sample rate header if specified\n if (sampleRate !== undefined) {\n headers['x-honeycomb-samplerate'] = String(sampleRate);\n }\n\n return {\n service,\n environment,\n version,\n protocol: 'grpc', // Honeycomb uses gRPC for better performance\n endpoint,\n headers,\n };\n}\n"]}
@@ -0,0 +1,136 @@
1
+ import { AutotelConfig } from 'autotel';
2
+
3
+ /**
4
+ * Honeycomb preset for autotel
5
+ *
6
+ * Provides a simplified configuration helper for Honeycomb integration
7
+ * with best practices built-in.
8
+ *
9
+ * @example Using Honeycomb with API key
10
+ * ```typescript
11
+ * import { init } from 'autotel';
12
+ * import { createHoneycombConfig } from 'autotel-backends/honeycomb';
13
+ *
14
+ * init(createHoneycombConfig({
15
+ * apiKey: process.env.HONEYCOMB_API_KEY!,
16
+ * service: 'my-app',
17
+ * }));
18
+ * ```
19
+ *
20
+ * @example With custom dataset
21
+ * ```typescript
22
+ * import { init } from 'autotel';
23
+ * import { createHoneycombConfig } from 'autotel-backends/honeycomb';
24
+ *
25
+ * init(createHoneycombConfig({
26
+ * apiKey: process.env.HONEYCOMB_API_KEY!,
27
+ * service: 'my-app',
28
+ * dataset: 'production',
29
+ * }));
30
+ * ```
31
+ */
32
+
33
+ /**
34
+ * Configuration options for Honeycomb preset
35
+ */
36
+ interface HoneycombPresetConfig {
37
+ /**
38
+ * Honeycomb API key (required).
39
+ *
40
+ * Get your API key from:
41
+ * https://ui.honeycomb.io/account
42
+ *
43
+ * For classic environments, use an environment-specific key.
44
+ * For newer environments, use a team-level API key.
45
+ */
46
+ apiKey: string;
47
+ /**
48
+ * Service name (required).
49
+ * Appears as service.name in Honeycomb traces and determines dataset routing.
50
+ */
51
+ service: string;
52
+ /**
53
+ * Dataset name (optional).
54
+ * For classic Honeycomb accounts that use datasets.
55
+ * Modern environments route based on service.name instead.
56
+ *
57
+ * @default service name
58
+ */
59
+ dataset?: string;
60
+ /**
61
+ * Deployment environment (e.g., 'production', 'staging', 'development').
62
+ * Used for environment filtering in Honeycomb.
63
+ *
64
+ * @default process.env.NODE_ENV || 'development'
65
+ */
66
+ environment?: string;
67
+ /**
68
+ * Service version for deployment tracking.
69
+ *
70
+ * @default process.env.VERSION || auto-detected from package.json
71
+ */
72
+ version?: string;
73
+ /**
74
+ * Honeycomb API endpoint.
75
+ * Use this to configure for different regions or on-premises installations.
76
+ *
77
+ * @default 'api.honeycomb.io:443'
78
+ */
79
+ endpoint?: string;
80
+ /**
81
+ * Sample rate for traces (1 = 100%, 10 = 10%, 100 = 1%).
82
+ * Honeycomb's head-based sampling rate.
83
+ *
84
+ * Note: Autotel uses tail-based sampling by default.
85
+ * This setting applies additional head-based sampling if specified.
86
+ *
87
+ * @default undefined (no head-based sampling, relies on tail sampling)
88
+ */
89
+ sampleRate?: number;
90
+ }
91
+ /**
92
+ * Create an autotel configuration optimized for Honeycomb.
93
+ *
94
+ * This preset handles:
95
+ * - gRPC protocol configuration (Honeycomb's preferred protocol)
96
+ * - Proper endpoint and authentication headers
97
+ * - Dataset routing (for classic accounts)
98
+ * - Unified service tagging (service, env, version)
99
+ *
100
+ * Honeycomb uses gRPC by default for better performance and lower overhead.
101
+ * This preset automatically configures the gRPC protocol.
102
+ *
103
+ * @param config - Honeycomb-specific configuration options
104
+ * @returns AutotelConfig ready to pass to init()
105
+ *
106
+ * @example Simple configuration
107
+ * ```typescript
108
+ * init(createHoneycombConfig({
109
+ * apiKey: process.env.HONEYCOMB_API_KEY!,
110
+ * service: 'my-app',
111
+ * }));
112
+ * ```
113
+ *
114
+ * @example With custom dataset and environment
115
+ * ```typescript
116
+ * init(createHoneycombConfig({
117
+ * apiKey: process.env.HONEYCOMB_API_KEY!,
118
+ * service: 'my-app',
119
+ * dataset: 'production',
120
+ * environment: 'production',
121
+ * version: '2.1.0',
122
+ * }));
123
+ * ```
124
+ *
125
+ * @example With sample rate
126
+ * ```typescript
127
+ * init(createHoneycombConfig({
128
+ * apiKey: process.env.HONEYCOMB_API_KEY!,
129
+ * service: 'my-app',
130
+ * sampleRate: 10, // Sample 10% of traces (head-based sampling)
131
+ * }));
132
+ * ```
133
+ */
134
+ declare function createHoneycombConfig(config: HoneycombPresetConfig): AutotelConfig;
135
+
136
+ export { type HoneycombPresetConfig, createHoneycombConfig };
package/dist/index.cjs ADDED
@@ -0,0 +1,327 @@
1
+ 'use strict';
2
+
3
+ var module$1 = require('module');
4
+
5
+ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
6
+ // src/honeycomb.ts
7
+ function createHoneycombConfig(config) {
8
+ const {
9
+ apiKey,
10
+ service,
11
+ dataset,
12
+ environment,
13
+ version,
14
+ endpoint = "api.honeycomb.io:443",
15
+ sampleRate
16
+ } = config;
17
+ if (!apiKey) {
18
+ throw new Error(
19
+ "Honeycomb API key is required. Get your API key from: https://ui.honeycomb.io/account"
20
+ );
21
+ }
22
+ const headers = {
23
+ "x-honeycomb-team": apiKey
24
+ };
25
+ if (dataset) {
26
+ headers["x-honeycomb-dataset"] = dataset;
27
+ }
28
+ if (sampleRate !== void 0) {
29
+ headers["x-honeycomb-samplerate"] = String(sampleRate);
30
+ }
31
+ return {
32
+ service,
33
+ environment,
34
+ version,
35
+ protocol: "grpc",
36
+ // Honeycomb uses gRPC for better performance
37
+ endpoint,
38
+ headers
39
+ };
40
+ }
41
+ function createDatadogConfig(config) {
42
+ const {
43
+ apiKey,
44
+ site = "datadoghq.com",
45
+ service,
46
+ environment,
47
+ version,
48
+ enableLogs = false,
49
+ useAgent = false,
50
+ agentHost = "localhost",
51
+ agentPort = 4318,
52
+ logRecordProcessors
53
+ } = config;
54
+ if (!useAgent && !apiKey) {
55
+ throw new Error(
56
+ "Datadog API key is required for direct cloud ingestion. Either provide apiKey or set useAgent: true to use local Datadog Agent."
57
+ );
58
+ }
59
+ const baseConfig = {
60
+ service,
61
+ environment,
62
+ version
63
+ };
64
+ if (useAgent) {
65
+ const agentEndpoint = `http://${agentHost}:${agentPort}`;
66
+ if (enableLogs) {
67
+ const logsEndpoint = `http://${agentHost}:${agentPort}/v1/logs`;
68
+ if (!process.env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT) {
69
+ process.env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT = logsEndpoint;
70
+ }
71
+ if (!process.env.OTEL_EXPORTER_OTLP_LOGS_PROTOCOL) {
72
+ process.env.OTEL_EXPORTER_OTLP_LOGS_PROTOCOL = "http/protobuf";
73
+ }
74
+ const resourceAttrs = [
75
+ `service.name=${service}`,
76
+ environment ? `deployment.environment=${environment}` : null,
77
+ version ? `service.version=${version}` : null
78
+ ].filter(Boolean).join(",");
79
+ if (!process.env.OTEL_RESOURCE_ATTRIBUTES) {
80
+ process.env.OTEL_RESOURCE_ATTRIBUTES = resourceAttrs;
81
+ }
82
+ }
83
+ return {
84
+ ...baseConfig,
85
+ endpoint: agentEndpoint
86
+ // No API key or headers needed - Agent handles authentication
87
+ };
88
+ }
89
+ const otlpEndpoint = `https://otlp.${site}`;
90
+ const authHeaders = `dd-api-key=${apiKey}`;
91
+ const cloudConfig = {
92
+ ...baseConfig,
93
+ endpoint: otlpEndpoint,
94
+ headers: authHeaders
95
+ };
96
+ if (enableLogs) {
97
+ const logsEndpoint = useAgent ? `http://${agentHost}:${agentPort}/v1/logs` : `https://otlp.${site}/v1/logs`;
98
+ if (!process.env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT) {
99
+ process.env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT = logsEndpoint;
100
+ }
101
+ if (!process.env.OTEL_EXPORTER_OTLP_LOGS_PROTOCOL) {
102
+ process.env.OTEL_EXPORTER_OTLP_LOGS_PROTOCOL = "http/protobuf";
103
+ }
104
+ if (!useAgent && apiKey && !process.env.OTEL_EXPORTER_OTLP_LOGS_HEADERS) {
105
+ process.env.OTEL_EXPORTER_OTLP_LOGS_HEADERS = `dd-api-key=${apiKey}`;
106
+ }
107
+ const resourceAttrs = [
108
+ `service.name=${service}`,
109
+ environment ? `deployment.environment=${environment}` : null,
110
+ version ? `service.version=${version}` : null
111
+ ].filter(Boolean).join(",");
112
+ if (!process.env.OTEL_RESOURCE_ATTRIBUTES) {
113
+ process.env.OTEL_RESOURCE_ATTRIBUTES = resourceAttrs;
114
+ }
115
+ if (logRecordProcessors) {
116
+ cloudConfig.logRecordProcessors = logRecordProcessors;
117
+ } else {
118
+ try {
119
+ const pkgRequire = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
120
+ const { BatchLogRecordProcessor } = pkgRequire(
121
+ "@opentelemetry/sdk-logs"
122
+ );
123
+ const { OTLPLogExporter } = pkgRequire(
124
+ "@opentelemetry/exporter-logs-otlp-http"
125
+ );
126
+ cloudConfig.logRecordProcessors = [
127
+ new BatchLogRecordProcessor(
128
+ new OTLPLogExporter({
129
+ url: `${otlpEndpoint}/v1/logs`,
130
+ headers: {
131
+ "dd-api-key": apiKey
132
+ }
133
+ })
134
+ )
135
+ ];
136
+ } catch {
137
+ throw new Error(
138
+ "Log export requires @opentelemetry/sdk-logs and @opentelemetry/exporter-logs-otlp-http. Install them or set enableLogs: false."
139
+ );
140
+ }
141
+ }
142
+ }
143
+ return cloudConfig;
144
+ }
145
+ var DEFAULT_ENDPOINT = "https://telemetry.googleapis.com";
146
+ function createGoogleCloudConfig(config) {
147
+ const {
148
+ projectId,
149
+ service,
150
+ environment,
151
+ version,
152
+ useCollector = false,
153
+ collectorEndpoint = "http://localhost:4318",
154
+ endpoint = DEFAULT_ENDPOINT
155
+ } = config;
156
+ if (!projectId) {
157
+ throw new Error(
158
+ "Google Cloud projectId is required. Set it or use process.env.GOOGLE_CLOUD_PROJECT."
159
+ );
160
+ }
161
+ const baseConfig = {
162
+ service,
163
+ environment,
164
+ version
165
+ };
166
+ if (useCollector) {
167
+ return {
168
+ ...baseConfig,
169
+ endpoint: collectorEndpoint,
170
+ // x-goog-user-project for quota when Collector forwards to GCP
171
+ headers: { "x-goog-user-project": projectId }
172
+ };
173
+ }
174
+ try {
175
+ const userRequire = module$1.createRequire(process.cwd() + "/package.json");
176
+ const { GoogleAuth } = userRequire("google-auth-library");
177
+ const { OTLPTraceExporter } = userRequire(
178
+ "@opentelemetry/exporter-trace-otlp-http"
179
+ );
180
+ const tracesUrl = `${endpoint}/v1/traces`;
181
+ const auth = new GoogleAuth({
182
+ scopes: ["https://www.googleapis.com/auth/cloud-platform"]
183
+ });
184
+ const gcpTraceExporter = createGcpAuthTraceExporter(
185
+ tracesUrl,
186
+ projectId,
187
+ auth,
188
+ OTLPTraceExporter
189
+ );
190
+ return {
191
+ ...baseConfig,
192
+ // Structurally compatible with SpanExporter from @opentelemetry/sdk-trace-base
193
+ spanExporters: [
194
+ gcpTraceExporter
195
+ ]
196
+ };
197
+ } catch (error) {
198
+ const message = error instanceof Error ? error.message : String(error);
199
+ if (message.includes("google-auth-library") || message.includes("Cannot find module")) {
200
+ throw new Error(
201
+ "Direct export to Google Cloud requires google-auth-library. Install it: pnpm add google-auth-library. Or use useCollector: true and run an OpenTelemetry Collector with GCP auth.",
202
+ { cause: error }
203
+ );
204
+ }
205
+ throw error;
206
+ }
207
+ }
208
+ function createGcpAuthTraceExporter(url, projectId, auth, OTLPTraceExporterCtor) {
209
+ return new GcpAuthSpanExporter(url, projectId, auth, OTLPTraceExporterCtor);
210
+ }
211
+ var GcpAuthSpanExporter = class {
212
+ constructor(url, projectId, auth, OTLPTraceExporterCtor) {
213
+ this.url = url;
214
+ this.projectId = projectId;
215
+ this.auth = auth;
216
+ this.OTLPTraceExporterCtor = OTLPTraceExporterCtor;
217
+ }
218
+ async export(spans, resultCallback) {
219
+ try {
220
+ const client = await this.auth.getClient();
221
+ const tokenResponse = await client.getAccessToken();
222
+ const token = tokenResponse.token;
223
+ if (!token) {
224
+ resultCallback({
225
+ code: 1,
226
+ error: new Error("No access token from ADC")
227
+ });
228
+ return;
229
+ }
230
+ const exporter = new this.OTLPTraceExporterCtor({
231
+ url: this.url,
232
+ headers: {
233
+ Authorization: `Bearer ${token}`,
234
+ "x-goog-user-project": this.projectId
235
+ }
236
+ });
237
+ exporter.export(spans, resultCallback);
238
+ } catch (error) {
239
+ resultCallback({
240
+ code: 1,
241
+ error: error instanceof Error ? error : new Error(String(error))
242
+ });
243
+ }
244
+ }
245
+ forceFlush() {
246
+ return Promise.resolve();
247
+ }
248
+ shutdown() {
249
+ return Promise.resolve();
250
+ }
251
+ };
252
+ function normalizeHeaders(headers) {
253
+ if (!headers) return void 0;
254
+ if (typeof headers === "object") return headers;
255
+ const out = {};
256
+ for (const pair of headers.split(",")) {
257
+ const [key, ...valueParts] = pair.split("=");
258
+ if (key && valueParts.length > 0) {
259
+ let value = valueParts.join("=").trim();
260
+ value = value.replaceAll("%20", " ");
261
+ out[key.trim()] = value;
262
+ }
263
+ }
264
+ return Object.keys(out).length > 0 ? out : void 0;
265
+ }
266
+ function createGrafanaConfig(config) {
267
+ const {
268
+ endpoint,
269
+ headers: headersInput,
270
+ service,
271
+ environment,
272
+ version,
273
+ enableLogs = true,
274
+ logRecordProcessors
275
+ } = config;
276
+ if (!endpoint) {
277
+ throw new Error(
278
+ "Grafana Cloud endpoint is required. Get it from: Grafana Cloud \u2192 your stack \u2192 Connections \u2192 OpenTelemetry \u2192 Configure"
279
+ );
280
+ }
281
+ const headers = normalizeHeaders(headersInput);
282
+ const base = endpoint.replace(/\/v1\/(traces|metrics|logs)$/, "");
283
+ const logsUrl = `${base}${base.endsWith("/") ? "" : "/"}v1/logs`;
284
+ const result = {
285
+ service,
286
+ environment,
287
+ version,
288
+ endpoint,
289
+ headers,
290
+ metrics: true
291
+ };
292
+ if (enableLogs) {
293
+ if (logRecordProcessors) {
294
+ result.logRecordProcessors = logRecordProcessors;
295
+ } else {
296
+ try {
297
+ const pkgRequire = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
298
+ const { BatchLogRecordProcessor } = pkgRequire(
299
+ "@opentelemetry/sdk-logs"
300
+ );
301
+ const { OTLPLogExporter } = pkgRequire(
302
+ "@opentelemetry/exporter-logs-otlp-http"
303
+ );
304
+ result.logRecordProcessors = [
305
+ new BatchLogRecordProcessor(
306
+ new OTLPLogExporter({
307
+ url: logsUrl,
308
+ headers
309
+ })
310
+ )
311
+ ];
312
+ } catch {
313
+ throw new Error(
314
+ "Log export requires @opentelemetry/sdk-logs and @opentelemetry/exporter-logs-otlp-http. Install them or set enableLogs: false."
315
+ );
316
+ }
317
+ }
318
+ }
319
+ return result;
320
+ }
321
+
322
+ exports.createDatadogConfig = createDatadogConfig;
323
+ exports.createGoogleCloudConfig = createGoogleCloudConfig;
324
+ exports.createGrafanaConfig = createGrafanaConfig;
325
+ exports.createHoneycombConfig = createHoneycombConfig;
326
+ //# sourceMappingURL=index.cjs.map
327
+ //# sourceMappingURL=index.cjs.map