autotel-backends 2.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Jag Reehal 2025
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,284 @@
1
+ # Autotel Backends
2
+
3
+ Vendor backend configurations for [Autotel](../autotel) - simplified setup helpers for popular observability platforms.
4
+
5
+ ## What are Backends?
6
+
7
+ **Backends** are vendor-specific configuration helpers that simplify setting up Autotel with observability platforms like Honeycomb, Datadog, New Relic, etc.
8
+
9
+ They handle:
10
+
11
+ - Correct endpoint URLs for each vendor
12
+ - Authentication headers and API key formats
13
+ - Protocol selection (gRPC vs HTTP)
14
+ - Region-specific configurations
15
+ - Best practice defaults
16
+
17
+ ### Backends vs Plugins
18
+
19
+ | Package | Purpose | Examples |
20
+ | -------------------- | ----------------------------------------------------- | --------------------------- |
21
+ | **autotel-backends** | Configure **where** telemetry goes (outputs) | Honeycomb, Datadog, Grafana |
22
+ | **autotel-plugins** | Instrument **libraries** to create telemetry (inputs) | Drizzle ORM, custom SDKs |
23
+
24
+ **Think of it this way**: Plugins create the data, backends send it somewhere.
25
+
26
+ ## Installation
27
+
28
+ ```bash
29
+ npm install autotel autotel-backends
30
+ ```
31
+
32
+ ## Quick Start
33
+
34
+ ### Honeycomb
35
+
36
+ ```typescript
37
+ import { init } from 'autotel';
38
+ import { createHoneycombConfig } from 'autotel-backends/honeycomb';
39
+
40
+ init(
41
+ createHoneycombConfig({
42
+ apiKey: process.env.HONEYCOMB_API_KEY!,
43
+ service: 'my-app',
44
+ }),
45
+ );
46
+ ```
47
+
48
+ ### Datadog
49
+
50
+ ```typescript
51
+ import { init } from 'autotel';
52
+ import { createDatadogConfig } from 'autotel-backends/datadog';
53
+
54
+ // Direct cloud ingestion (serverless, edge)
55
+ init(
56
+ createDatadogConfig({
57
+ apiKey: process.env.DATADOG_API_KEY!,
58
+ service: 'my-lambda',
59
+ }),
60
+ );
61
+
62
+ // Or use local Datadog Agent (Kubernetes, long-running services)
63
+ init(
64
+ createDatadogConfig({
65
+ service: 'my-api',
66
+ useAgent: true,
67
+ }),
68
+ );
69
+ ```
70
+
71
+ ## Available Backends
72
+
73
+ ### 🍯 Honeycomb
74
+
75
+ [Honeycomb](https://honeycomb.io) provides powerful distributed tracing and observability.
76
+
77
+ ```typescript
78
+ import { createHoneycombConfig } from 'autotel-backends/honeycomb';
79
+
80
+ init(
81
+ createHoneycombConfig({
82
+ apiKey: process.env.HONEYCOMB_API_KEY!,
83
+ service: 'my-app',
84
+ environment: 'production',
85
+ version: '1.0.0',
86
+ dataset: 'my-dataset', // Optional: for classic accounts
87
+ }),
88
+ );
89
+ ```
90
+
91
+ **Features**:
92
+
93
+ - Auto-configures gRPC protocol (Honeycomb's preferred)
94
+ - Supports both classic datasets and modern service-based routing
95
+ - Environment and version tagging
96
+ - Head-based sampling configuration
97
+
98
+ [View full Honeycomb configuration options →](./src/honeycomb.ts)
99
+
100
+ ### 🐕 Datadog
101
+
102
+ [Datadog](https://datadoghq.com) provides comprehensive APM, infrastructure monitoring, and logs.
103
+
104
+ ```typescript
105
+ import { createDatadogConfig } from 'autotel-backends/datadog';
106
+
107
+ // Cloud ingestion (best for serverless/edge)
108
+ init(
109
+ createDatadogConfig({
110
+ apiKey: process.env.DATADOG_API_KEY!,
111
+ site: 'datadoghq.com', // or 'datadoghq.eu', 'us3.datadoghq.com', etc.
112
+ service: 'my-lambda',
113
+ environment: 'production',
114
+ enableLogs: true, // Optional: also send logs
115
+ }),
116
+ );
117
+
118
+ // Agent-based (best for Kubernetes/VMs)
119
+ init(
120
+ createDatadogConfig({
121
+ service: 'my-api',
122
+ useAgent: true,
123
+ agentHost: 'localhost', // or 'datadog-agent.default.svc.cluster.local'
124
+ agentPort: 4318,
125
+ }),
126
+ );
127
+ ```
128
+
129
+ **Features**:
130
+
131
+ - Direct cloud ingestion OR local agent
132
+ - Multi-region support (US1, US3, US5, EU, AP1, FedRAMP)
133
+ - Unified service tagging (service, env, version)
134
+ - Optional log export via OTLP
135
+ - Kubernetes-friendly agent configuration
136
+
137
+ [View full Datadog configuration options →](./src/datadog.ts)
138
+
139
+ ## Why Use Backend Configs?
140
+
141
+ ### Without backend configs (manual):
142
+
143
+ ```typescript
144
+ import { init } from 'autotel';
145
+
146
+ init({
147
+ service: 'my-app',
148
+ endpoint: 'https://api.honeycomb.io:443',
149
+ protocol: 'grpc',
150
+ otlpHeaders: {
151
+ 'x-honeycomb-team': process.env.HONEYCOMB_API_KEY!,
152
+ 'x-honeycomb-dataset': 'production',
153
+ },
154
+ environment: 'production',
155
+ version: '1.0.0',
156
+ });
157
+ ```
158
+
159
+ ### With backend configs:
160
+
161
+ ```typescript
162
+ import { init } from 'autotel';
163
+ import { createHoneycombConfig } from 'autotel-backends/honeycomb';
164
+
165
+ init(
166
+ createHoneycombConfig({
167
+ apiKey: process.env.HONEYCOMB_API_KEY!,
168
+ service: 'my-app',
169
+ environment: 'production',
170
+ version: '1.0.0',
171
+ }),
172
+ );
173
+ ```
174
+
175
+ **Benefits**:
176
+
177
+ - Less code, fewer mistakes
178
+ - Vendor best practices built-in
179
+ - Validated configurations
180
+ - Easy to switch vendors
181
+
182
+ ## Using Environment Variables
183
+
184
+ All backends work great with environment variables:
185
+
186
+ ```typescript
187
+ import { createHoneycombConfig } from 'autotel-backends/honeycomb';
188
+
189
+ init(
190
+ createHoneycombConfig({
191
+ apiKey: process.env.HONEYCOMB_API_KEY!,
192
+ service: process.env.SERVICE_NAME || 'my-app',
193
+ environment: process.env.NODE_ENV,
194
+ }),
195
+ );
196
+ ```
197
+
198
+ Or use Autotel's built-in env var support:
199
+
200
+ ```bash
201
+ # .env
202
+ OTEL_SERVICE_NAME=my-app
203
+ OTEL_EXPORTER_OTLP_ENDPOINT=https://api.honeycomb.io
204
+ OTEL_EXPORTER_OTLP_HEADERS=x-honeycomb-team=YOUR_API_KEY
205
+ ```
206
+
207
+ ```typescript
208
+ import { init } from 'autotel';
209
+
210
+ // Reads from env vars automatically
211
+ init({});
212
+ ```
213
+
214
+ ## Migration from autotel/presets
215
+
216
+ If you were using `autotel/presets/*`, migration is simple:
217
+
218
+ **Before** (v1.x):
219
+
220
+ ```typescript
221
+ import { createHoneycombConfig } from 'autotel/presets/honeycomb';
222
+ ```
223
+
224
+ **After** (v2.x):
225
+
226
+ ```bash
227
+ npm install autotel-backends
228
+ ```
229
+
230
+ ```typescript
231
+ import { createHoneycombConfig } from 'autotel-backends/honeycomb';
232
+ ```
233
+
234
+ The configuration options are **identical** - only the import path changed.
235
+
236
+ ## Philosophy
237
+
238
+ Autotel follows the principle: **"Write once, observe everywhere"**.
239
+
240
+ Backend configurations are:
241
+
242
+ - **Optional**: Use raw `init()` config if you prefer
243
+ - **Vendor-agnostic at core**: Keeping these separate maintains the vendor-neutral philosophy
244
+ - **Best practices**: Configurations follow vendor recommendations
245
+ - **Tree-shakeable**: Import only what you need
246
+
247
+ ## TypeScript
248
+
249
+ Full type safety with TypeScript:
250
+
251
+ ```typescript
252
+ import type {
253
+ HoneycombPresetConfig,
254
+ DatadogPresetConfig,
255
+ } from 'autotel-backends';
256
+
257
+ const honeycombConfig: HoneycombPresetConfig = {
258
+ apiKey: process.env.HONEYCOMB_API_KEY!,
259
+ service: 'my-app',
260
+ };
261
+
262
+ const datadogConfig: DatadogPresetConfig = {
263
+ apiKey: process.env.DATADOG_API_KEY!,
264
+ service: 'my-app',
265
+ site: 'datadoghq.com',
266
+ };
267
+ ```
268
+
269
+ ## Contributing
270
+
271
+ Want to add a new backend configuration? Please [open an issue](https://github.com/jagreehal/autotel/issues) to discuss.
272
+
273
+ Popular backends we'd love to support:
274
+
275
+ - Grafana Cloud
276
+ - New Relic
277
+ - Lightstep
278
+ - Elastic APM
279
+ - AWS X-Ray
280
+ - Google Cloud Trace
281
+
282
+ ## License
283
+
284
+ MIT
@@ -0,0 +1,160 @@
1
+ import { AutotelConfig } from 'autotel';
2
+ import { LogRecordProcessor } from '@opentelemetry/sdk-logs';
3
+
4
+ /**
5
+ * Datadog preset for autotel
6
+ *
7
+ * Provides a simplified configuration helper for Datadog integration
8
+ * with best practices built-in.
9
+ *
10
+ * @example Direct cloud ingestion (serverless, edge)
11
+ * ```typescript
12
+ * import { init } from 'autotel';
13
+ * import { createDatadogConfig } from 'autotel-backends/datadog';
14
+ *
15
+ * init(createDatadogConfig({
16
+ * apiKey: process.env.DATADOG_API_KEY!,
17
+ * service: 'my-lambda',
18
+ * enableLogs: true,
19
+ * }));
20
+ * ```
21
+ *
22
+ * @example Local Datadog Agent (long-running services, Kubernetes)
23
+ * ```typescript
24
+ * import { init } from 'autotel';
25
+ * import { createDatadogConfig } from 'autotel-backends/datadog';
26
+ *
27
+ * init(createDatadogConfig({
28
+ * service: 'my-api',
29
+ * useAgent: true, // No API key needed - Agent handles it
30
+ * }));
31
+ * ```
32
+ */
33
+
34
+ /**
35
+ * Datadog site regions
36
+ */
37
+ type DatadogSite = 'datadoghq.com' | 'datadoghq.eu' | 'us3.datadoghq.com' | 'us5.datadoghq.com' | 'ap1.datadoghq.com' | 'ddog-gov.com';
38
+ /**
39
+ * Configuration options for Datadog preset
40
+ */
41
+ interface DatadogPresetConfig {
42
+ /**
43
+ * Datadog API key (required for direct cloud ingestion).
44
+ * Not needed if using local Datadog Agent (useAgent: true).
45
+ *
46
+ * Get your API key from:
47
+ * https://app.datadoghq.com/organization-settings/api-keys
48
+ */
49
+ apiKey?: string;
50
+ /**
51
+ * Datadog site/region.
52
+ * Determines which Datadog intake endpoint to use.
53
+ *
54
+ * @default 'datadoghq.com' (US1)
55
+ */
56
+ site?: DatadogSite;
57
+ /**
58
+ * Service name (required).
59
+ * Appears in Datadog APM, Service Catalog, and all telemetry.
60
+ */
61
+ service: string;
62
+ /**
63
+ * Deployment environment (e.g., 'production', 'staging', 'development').
64
+ * Used for environment filtering in Datadog.
65
+ *
66
+ * @default process.env.DD_ENV || process.env.NODE_ENV || 'development'
67
+ */
68
+ environment?: string;
69
+ /**
70
+ * Service version for deployment tracking.
71
+ * Enables Deployment Tracking in Datadog APM.
72
+ *
73
+ * @default process.env.DD_VERSION || auto-detected from package.json
74
+ */
75
+ version?: string;
76
+ /**
77
+ * Enable log export to Datadog via OTLP.
78
+ * Requires peer dependencies: @opentelemetry/sdk-logs, @opentelemetry/exporter-logs-otlp-http
79
+ *
80
+ * @default false
81
+ */
82
+ enableLogs?: boolean;
83
+ /**
84
+ * Use local Datadog Agent instead of direct cloud ingestion.
85
+ *
86
+ * Benefits:
87
+ * - Lower egress costs (Agent aggregates locally)
88
+ * - Advanced features: trace-log correlation, multi-line logs, data scrubbing
89
+ * - 500+ integrations for enrichment
90
+ * - Infrastructure metrics collection
91
+ *
92
+ * Requires: Datadog Agent 7.35+ with OTLP enabled
93
+ *
94
+ * @default false
95
+ */
96
+ useAgent?: boolean;
97
+ /**
98
+ * Datadog Agent hostname (when useAgent: true).
99
+ *
100
+ * @default 'localhost'
101
+ */
102
+ agentHost?: string;
103
+ /**
104
+ * Datadog Agent OTLP port (when useAgent: true).
105
+ *
106
+ * @default 4318 (OTLP HTTP)
107
+ */
108
+ agentPort?: number;
109
+ /**
110
+ * Custom log record processors (advanced).
111
+ * Overrides the default log processor if enableLogs is true.
112
+ */
113
+ logRecordProcessors?: LogRecordProcessor[];
114
+ }
115
+ /**
116
+ * Create an autotel configuration optimized for Datadog.
117
+ *
118
+ * This preset handles:
119
+ * - Proper OTLP endpoint configuration (Agent vs direct ingestion)
120
+ * - Direct: https://otlp.{site} → SDK appends /v1/traces, /v1/metrics, /v1/logs
121
+ * - Agent: http://localhost:4318 (default)
122
+ * - Datadog API key authentication headers (direct ingestion only)
123
+ * - Unified service tagging (service, env, version)
124
+ * - Resource attribute best practices
125
+ * - Optional log export configuration
126
+ *
127
+ * @param config - Datadog-specific configuration options
128
+ * @returns AutotelConfig ready to pass to init()
129
+ *
130
+ * @example Simple cloud ingestion
131
+ * ```typescript
132
+ * init(createDatadogConfig({
133
+ * apiKey: process.env.DATADOG_API_KEY!,
134
+ * service: 'my-app',
135
+ * }));
136
+ * ```
137
+ *
138
+ * @example With logs and custom environment
139
+ * ```typescript
140
+ * init(createDatadogConfig({
141
+ * apiKey: process.env.DATADOG_API_KEY!,
142
+ * service: 'my-app',
143
+ * environment: 'production',
144
+ * version: '2.1.0',
145
+ * enableLogs: true,
146
+ * }));
147
+ * ```
148
+ *
149
+ * @example Using local Datadog Agent
150
+ * ```typescript
151
+ * init(createDatadogConfig({
152
+ * service: 'my-api',
153
+ * useAgent: true,
154
+ * agentHost: 'datadog-agent.default.svc.cluster.local', // Kubernetes
155
+ * }));
156
+ * ```
157
+ */
158
+ declare function createDatadogConfig(config: DatadogPresetConfig): AutotelConfig;
159
+
160
+ export { type DatadogPresetConfig, type DatadogSite, createDatadogConfig };
@@ -0,0 +1,77 @@
1
+ import { createRequire } from 'module';
2
+
3
+ // src/datadog.ts
4
+ function createDatadogConfig(config) {
5
+ const {
6
+ apiKey,
7
+ site = "datadoghq.com",
8
+ service,
9
+ environment,
10
+ version,
11
+ enableLogs = false,
12
+ useAgent = false,
13
+ agentHost = "localhost",
14
+ agentPort = 4318,
15
+ logRecordProcessors
16
+ } = config;
17
+ if (!useAgent && !apiKey) {
18
+ throw new Error(
19
+ "Datadog API key is required for direct cloud ingestion. Either provide apiKey or set useAgent: true to use local Datadog Agent."
20
+ );
21
+ }
22
+ const baseConfig = {
23
+ service,
24
+ environment,
25
+ version
26
+ };
27
+ if (useAgent) {
28
+ const agentEndpoint = `http://${agentHost}:${agentPort}`;
29
+ return {
30
+ ...baseConfig,
31
+ endpoint: agentEndpoint
32
+ // No API key or headers needed - Agent handles authentication
33
+ };
34
+ }
35
+ const otlpEndpoint = `https://otlp.${site}`;
36
+ const authHeaders = `dd-api-key=${apiKey}`;
37
+ const cloudConfig = {
38
+ ...baseConfig,
39
+ endpoint: otlpEndpoint,
40
+ otlpHeaders: authHeaders
41
+ };
42
+ if (enableLogs) {
43
+ if (logRecordProcessors) {
44
+ cloudConfig.logRecordProcessors = logRecordProcessors;
45
+ } else {
46
+ try {
47
+ const userRequire = createRequire(process.cwd() + "/package.json");
48
+ const { BatchLogRecordProcessor } = userRequire(
49
+ "@opentelemetry/sdk-logs"
50
+ );
51
+ const { OTLPLogExporter } = userRequire(
52
+ "@opentelemetry/exporter-logs-otlp-http"
53
+ );
54
+ cloudConfig.logRecordProcessors = [
55
+ new BatchLogRecordProcessor(
56
+ new OTLPLogExporter({
57
+ // Logs use /v1/logs path (SDK appends this to endpoint)
58
+ url: `${otlpEndpoint}/v1/logs`,
59
+ headers: {
60
+ "dd-api-key": apiKey
61
+ }
62
+ })
63
+ )
64
+ ];
65
+ } catch {
66
+ throw new Error(
67
+ "Log export requires peer dependencies: @opentelemetry/sdk-logs and @opentelemetry/exporter-logs-otlp-http. Install them with: npm install @opentelemetry/sdk-logs @opentelemetry/exporter-logs-otlp-http"
68
+ );
69
+ }
70
+ }
71
+ }
72
+ return cloudConfig;
73
+ }
74
+
75
+ export { createDatadogConfig };
76
+ //# sourceMappingURL=datadog.js.map
77
+ //# sourceMappingURL=datadog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/datadog.ts"],"names":[],"mappings":";;;AA+KO,SAAS,oBACd,MAAA,EACe;AACf,EAAA,MAAM;AAAA,IACJ,MAAA;AAAA,IACA,IAAA,GAAO,eAAA;AAAA,IACP,OAAA;AAAA,IACA,WAAA;AAAA,IACA,OAAA;AAAA,IACA,UAAA,GAAa,KAAA;AAAA,IACb,QAAA,GAAW,KAAA;AAAA,IACX,SAAA,GAAY,WAAA;AAAA,IACZ,SAAA,GAAY,IAAA;AAAA,IACZ;AAAA,GACF,GAAI,MAAA;AAGJ,EAAA,IAAI,CAAC,QAAA,IAAY,CAAC,MAAA,EAAQ;AACxB,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KAEF;AAAA,EACF;AAEA,EAAA,MAAM,UAAA,GAA4B;AAAA,IAChC,OAAA;AAAA,IACA,WAAA;AAAA,IACA;AAAA,GACF;AAGA,EAAA,IAAI,QAAA,EAAU;AACZ,IAAA,MAAM,aAAA,GAAgB,CAAA,OAAA,EAAU,SAAS,CAAA,CAAA,EAAI,SAAS,CAAA,CAAA;AAEtD,IAAA,OAAO;AAAA,MACL,GAAG,UAAA;AAAA,MACH,QAAA,EAAU;AAAA;AAAA,KAEZ;AAAA,EACF;AAIA,EAAA,MAAM,YAAA,GAAe,gBAAgB,IAAI,CAAA,CAAA;AACzC,EAAA,MAAM,WAAA,GAAc,cAAc,MAAM,CAAA,CAAA;AAExC,EAAA,MAAM,WAAA,GAA6B;AAAA,IACjC,GAAG,UAAA;AAAA,IACH,QAAA,EAAU,YAAA;AAAA,IACV,WAAA,EAAa;AAAA,GACf;AAGA,EAAA,IAAI,UAAA,EAAY;AACd,IAAA,IAAI,mBAAA,EAAqB;AAEvB,MAAA,WAAA,CAAY,mBAAA,GAAsB,mBAAA;AAAA,IACpC,CAAA,MAAO;AAEL,MAAA,IAAI;AAGF,QAAA,MAAM,WAAA,GAAc,aAAA,CAAc,OAAA,CAAQ,GAAA,KAAQ,eAAe,CAAA;AAEjE,QAAA,MAAM,EAAE,yBAAwB,GAAI,WAAA;AAAA,UAClC;AAAA,SACF;AACA,QAAA,MAAM,EAAE,iBAAgB,GAAI,WAAA;AAAA,UAC1B;AAAA,SACF;AAEA,QAAA,WAAA,CAAY,mBAAA,GAAsB;AAAA,UAChC,IAAI,uBAAA;AAAA,YACF,IAAI,eAAA,CAAgB;AAAA;AAAA,cAElB,GAAA,EAAK,GAAG,YAAY,CAAA,QAAA,CAAA;AAAA,cACpB,OAAA,EAAS;AAAA,gBACP,YAAA,EAAc;AAAA;AAChB,aACD;AAAA;AACH,SACF;AAAA,MACF,CAAA,CAAA,MAAQ;AACN,QAAA,MAAM,IAAI,KAAA;AAAA,UACR;AAAA,SAEF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,EAAA,OAAO,WAAA;AACT","file":"datadog.js","sourcesContent":["/**\n * Datadog preset for autotel\n *\n * Provides a simplified configuration helper for Datadog integration\n * with best practices built-in.\n *\n * @example Direct cloud ingestion (serverless, edge)\n * ```typescript\n * import { init } from 'autotel';\n * import { createDatadogConfig } from 'autotel-backends/datadog';\n *\n * init(createDatadogConfig({\n * apiKey: process.env.DATADOG_API_KEY!,\n * service: 'my-lambda',\n * enableLogs: true,\n * }));\n * ```\n *\n * @example Local Datadog Agent (long-running services, Kubernetes)\n * ```typescript\n * import { init } from 'autotel';\n * import { createDatadogConfig } from 'autotel-backends/datadog';\n *\n * init(createDatadogConfig({\n * service: 'my-api',\n * useAgent: true, // No API key needed - Agent handles it\n * }));\n * ```\n */\n\nimport { createRequire } from 'node:module';\nimport type { AutotelConfig } from 'autotel';\nimport type { LogRecordProcessor } from '@opentelemetry/sdk-logs';\n\n/**\n * Datadog site regions\n */\nexport type DatadogSite =\n | 'datadoghq.com' // US1 (default)\n | 'datadoghq.eu' // EU\n | 'us3.datadoghq.com' // US3\n | 'us5.datadoghq.com' // US5\n | 'ap1.datadoghq.com' // AP1\n | 'ddog-gov.com'; // US1-FED\n\n/**\n * Configuration options for Datadog preset\n */\nexport interface DatadogPresetConfig {\n /**\n * Datadog API key (required for direct cloud ingestion).\n * Not needed if using local Datadog Agent (useAgent: true).\n *\n * Get your API key from:\n * https://app.datadoghq.com/organization-settings/api-keys\n */\n apiKey?: string;\n\n /**\n * Datadog site/region.\n * Determines which Datadog intake endpoint to use.\n *\n * @default 'datadoghq.com' (US1)\n */\n site?: DatadogSite;\n\n /**\n * Service name (required).\n * Appears in Datadog APM, Service Catalog, and all telemetry.\n */\n service: string;\n\n /**\n * Deployment environment (e.g., 'production', 'staging', 'development').\n * Used for environment filtering in Datadog.\n *\n * @default process.env.DD_ENV || process.env.NODE_ENV || 'development'\n */\n environment?: string;\n\n /**\n * Service version for deployment tracking.\n * Enables Deployment Tracking in Datadog APM.\n *\n * @default process.env.DD_VERSION || auto-detected from package.json\n */\n version?: string;\n\n /**\n * Enable log export to Datadog via OTLP.\n * Requires peer dependencies: @opentelemetry/sdk-logs, @opentelemetry/exporter-logs-otlp-http\n *\n * @default false\n */\n enableLogs?: boolean;\n\n /**\n * Use local Datadog Agent instead of direct cloud ingestion.\n *\n * Benefits:\n * - Lower egress costs (Agent aggregates locally)\n * - Advanced features: trace-log correlation, multi-line logs, data scrubbing\n * - 500+ integrations for enrichment\n * - Infrastructure metrics collection\n *\n * Requires: Datadog Agent 7.35+ with OTLP enabled\n *\n * @default false\n */\n useAgent?: boolean;\n\n /**\n * Datadog Agent hostname (when useAgent: true).\n *\n * @default 'localhost'\n */\n agentHost?: string;\n\n /**\n * Datadog Agent OTLP port (when useAgent: true).\n *\n * @default 4318 (OTLP HTTP)\n */\n agentPort?: number;\n\n /**\n * Custom log record processors (advanced).\n * Overrides the default log processor if enableLogs is true.\n */\n logRecordProcessors?: LogRecordProcessor[];\n}\n\n/**\n * Create an autotel configuration optimized for Datadog.\n *\n * This preset handles:\n * - Proper OTLP endpoint configuration (Agent vs direct ingestion)\n * - Direct: https://otlp.{site} → SDK appends /v1/traces, /v1/metrics, /v1/logs\n * - Agent: http://localhost:4318 (default)\n * - Datadog API key authentication headers (direct ingestion only)\n * - Unified service tagging (service, env, version)\n * - Resource attribute best practices\n * - Optional log export configuration\n *\n * @param config - Datadog-specific configuration options\n * @returns AutotelConfig ready to pass to init()\n *\n * @example Simple cloud ingestion\n * ```typescript\n * init(createDatadogConfig({\n * apiKey: process.env.DATADOG_API_KEY!,\n * service: 'my-app',\n * }));\n * ```\n *\n * @example With logs and custom environment\n * ```typescript\n * init(createDatadogConfig({\n * apiKey: process.env.DATADOG_API_KEY!,\n * service: 'my-app',\n * environment: 'production',\n * version: '2.1.0',\n * enableLogs: true,\n * }));\n * ```\n *\n * @example Using local Datadog Agent\n * ```typescript\n * init(createDatadogConfig({\n * service: 'my-api',\n * useAgent: true,\n * agentHost: 'datadog-agent.default.svc.cluster.local', // Kubernetes\n * }));\n * ```\n */\nexport function createDatadogConfig(\n config: DatadogPresetConfig,\n): AutotelConfig {\n const {\n apiKey,\n site = 'datadoghq.com',\n service,\n environment,\n version,\n enableLogs = false,\n useAgent = false,\n agentHost = 'localhost',\n agentPort = 4318,\n logRecordProcessors,\n } = config;\n\n // Validation: API key required for direct ingestion\n if (!useAgent && !apiKey) {\n throw new Error(\n 'Datadog API key is required for direct cloud ingestion. ' +\n 'Either provide apiKey or set useAgent: true to use local Datadog Agent.',\n );\n }\n\n const baseConfig: AutotelConfig = {\n service,\n environment,\n version,\n };\n\n // Local Datadog Agent configuration\n if (useAgent) {\n const agentEndpoint = `http://${agentHost}:${agentPort}`;\n\n return {\n ...baseConfig,\n endpoint: agentEndpoint,\n // No API key or headers needed - Agent handles authentication\n };\n }\n\n // Direct cloud ingestion configuration\n // Datadog OTLP endpoint: base URL without path (SDK appends /v1/traces, /v1/metrics, /v1/logs)\n const otlpEndpoint = `https://otlp.${site}`;\n const authHeaders = `dd-api-key=${apiKey}`;\n\n const cloudConfig: AutotelConfig = {\n ...baseConfig,\n endpoint: otlpEndpoint,\n otlpHeaders: authHeaders,\n };\n\n // Add log export if enabled\n if (enableLogs) {\n if (logRecordProcessors) {\n // Use custom processors if provided\n cloudConfig.logRecordProcessors = logRecordProcessors;\n } else {\n // Create default OTLP log exporter\n try {\n // Lazy-load to preserve optional peer dependencies\n // Use createRequire to resolve from user's project directory\n const userRequire = createRequire(process.cwd() + '/package.json');\n\n const { BatchLogRecordProcessor } = userRequire(\n '@opentelemetry/sdk-logs',\n );\n const { OTLPLogExporter } = userRequire(\n '@opentelemetry/exporter-logs-otlp-http',\n );\n\n cloudConfig.logRecordProcessors = [\n new BatchLogRecordProcessor(\n new OTLPLogExporter({\n // Logs use /v1/logs path (SDK appends this to endpoint)\n url: `${otlpEndpoint}/v1/logs`,\n headers: {\n 'dd-api-key': apiKey,\n },\n }),\n ),\n ];\n } catch {\n throw new Error(\n 'Log export requires peer dependencies: @opentelemetry/sdk-logs and @opentelemetry/exporter-logs-otlp-http. ' +\n 'Install them with: npm install @opentelemetry/sdk-logs @opentelemetry/exporter-logs-otlp-http',\n );\n }\n }\n }\n\n return cloudConfig;\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 };