autotel-backends 2.12.29 → 2.12.30
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/dist/datadog.cjs +134 -112
- package/dist/datadog.cjs.map +1 -1
- package/dist/datadog.d.cts +93 -121
- package/dist/datadog.d.cts.map +1 -0
- package/dist/datadog.d.ts +93 -121
- package/dist/datadog.d.ts.map +1 -0
- package/dist/datadog.js +133 -109
- package/dist/datadog.js.map +1 -1
- package/dist/google-cloud.cjs +114 -112
- package/dist/google-cloud.cjs.map +1 -1
- package/dist/google-cloud.d.cts +51 -77
- package/dist/google-cloud.d.cts.map +1 -0
- package/dist/google-cloud.d.ts +51 -77
- package/dist/google-cloud.d.ts.map +1 -0
- package/dist/google-cloud.js +113 -110
- package/dist/google-cloud.js.map +1 -1
- package/dist/grafana.cjs +75 -75
- package/dist/grafana.cjs.map +1 -1
- package/dist/grafana.d.cts +48 -69
- package/dist/grafana.d.cts.map +1 -0
- package/dist/grafana.d.ts +48 -69
- package/dist/grafana.d.ts.map +1 -0
- package/dist/grafana.js +74 -72
- package/dist/grafana.js.map +1 -1
- package/dist/honeycomb.cjs +60 -37
- package/dist/honeycomb.cjs.map +1 -1
- package/dist/honeycomb.d.cts +58 -86
- package/dist/honeycomb.d.cts.map +1 -0
- package/dist/honeycomb.d.ts +58 -86
- package/dist/honeycomb.d.ts.map +1 -0
- package/dist/honeycomb.js +59 -35
- package/dist/honeycomb.js.map +1 -1
- package/dist/index.cjs +9 -335
- package/dist/index.d.cts +5 -6
- package/dist/index.d.ts +5 -6
- package/dist/index.js +4 -328
- package/package.json +5 -5
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
package/dist/datadog.d.ts
CHANGED
|
@@ -1,36 +1,7 @@
|
|
|
1
|
-
import { AutotelConfig } from
|
|
2
|
-
import { LogRecordProcessor } from
|
|
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
|
-
*/
|
|
1
|
+
import { AutotelConfig } from "autotel";
|
|
2
|
+
import { LogRecordProcessor } from "@opentelemetry/sdk-logs";
|
|
33
3
|
|
|
4
|
+
//#region src/datadog.d.ts
|
|
34
5
|
/**
|
|
35
6
|
* Datadog site regions
|
|
36
7
|
*/
|
|
@@ -39,93 +10,93 @@ type DatadogSite = 'datadoghq.com' | 'datadoghq.eu' | 'us3.datadoghq.com' | 'us5
|
|
|
39
10
|
* Configuration options for Datadog preset
|
|
40
11
|
*/
|
|
41
12
|
interface DatadogPresetConfig {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Datadog API key (required for direct cloud ingestion).
|
|
15
|
+
* Not needed if using local Datadog Agent (useAgent: true).
|
|
16
|
+
*
|
|
17
|
+
* Get your API key from:
|
|
18
|
+
* https://app.datadoghq.com/organization-settings/api-keys
|
|
19
|
+
*/
|
|
20
|
+
apiKey?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Datadog site/region.
|
|
23
|
+
* Determines which Datadog intake endpoint to use.
|
|
24
|
+
*
|
|
25
|
+
* @default 'datadoghq.com' (US1)
|
|
26
|
+
*/
|
|
27
|
+
site?: DatadogSite;
|
|
28
|
+
/**
|
|
29
|
+
* Service name (required).
|
|
30
|
+
* Appears in Datadog APM, Service Catalog, and all telemetry.
|
|
31
|
+
*/
|
|
32
|
+
service: string;
|
|
33
|
+
/**
|
|
34
|
+
* Deployment environment (e.g., 'production', 'staging', 'development').
|
|
35
|
+
* Used for environment filtering in Datadog.
|
|
36
|
+
*
|
|
37
|
+
* @default process.env.DD_ENV || process.env.NODE_ENV || 'development'
|
|
38
|
+
*/
|
|
39
|
+
environment?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Service version for deployment tracking.
|
|
42
|
+
* Enables Deployment Tracking in Datadog APM.
|
|
43
|
+
*
|
|
44
|
+
* @default process.env.DD_VERSION || auto-detected from package.json
|
|
45
|
+
*/
|
|
46
|
+
version?: string;
|
|
47
|
+
/**
|
|
48
|
+
* Enable log export to Datadog via OTLP.
|
|
49
|
+
*
|
|
50
|
+
* When enabled, this:
|
|
51
|
+
* 1. Sets up OTel Logs SDK with OTLP exporter (for direct OTel logs API usage)
|
|
52
|
+
* 2. Auto-configures OTEL_EXPORTER_OTLP_LOGS_* env vars for pino-opentelemetry-transport
|
|
53
|
+
*
|
|
54
|
+
* For Pino users: Just add pino-opentelemetry-transport to your logger config:
|
|
55
|
+
* ```typescript
|
|
56
|
+
* const logger = pino({
|
|
57
|
+
* transport: {
|
|
58
|
+
* targets: [
|
|
59
|
+
* { target: 'pino-pretty' },
|
|
60
|
+
* { target: 'pino-opentelemetry-transport' }, // Auto-configured!
|
|
61
|
+
* ],
|
|
62
|
+
* },
|
|
63
|
+
* });
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* @default false
|
|
67
|
+
*/
|
|
68
|
+
enableLogs?: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Use local Datadog Agent instead of direct cloud ingestion.
|
|
71
|
+
*
|
|
72
|
+
* Benefits:
|
|
73
|
+
* - Lower egress costs (Agent aggregates locally)
|
|
74
|
+
* - Advanced features: trace-log correlation, multi-line logs, data scrubbing
|
|
75
|
+
* - 500+ integrations for enrichment
|
|
76
|
+
* - Infrastructure metrics collection
|
|
77
|
+
*
|
|
78
|
+
* Requires: Datadog Agent 7.35+ with OTLP enabled
|
|
79
|
+
*
|
|
80
|
+
* @default false
|
|
81
|
+
*/
|
|
82
|
+
useAgent?: boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Datadog Agent hostname (when useAgent: true).
|
|
85
|
+
*
|
|
86
|
+
* @default 'localhost'
|
|
87
|
+
*/
|
|
88
|
+
agentHost?: string;
|
|
89
|
+
/**
|
|
90
|
+
* Datadog Agent OTLP port (when useAgent: true).
|
|
91
|
+
*
|
|
92
|
+
* @default 4318 (OTLP HTTP)
|
|
93
|
+
*/
|
|
94
|
+
agentPort?: number;
|
|
95
|
+
/**
|
|
96
|
+
* Custom log record processors (advanced).
|
|
97
|
+
* Overrides the default log processor if enableLogs is true.
|
|
98
|
+
*/
|
|
99
|
+
logRecordProcessors?: LogRecordProcessor[];
|
|
129
100
|
}
|
|
130
101
|
/**
|
|
131
102
|
* Create an autotel configuration optimized for Datadog.
|
|
@@ -171,5 +142,6 @@ interface DatadogPresetConfig {
|
|
|
171
142
|
* ```
|
|
172
143
|
*/
|
|
173
144
|
declare function createDatadogConfig(config: DatadogPresetConfig): AutotelConfig;
|
|
174
|
-
|
|
175
|
-
export {
|
|
145
|
+
//#endregion
|
|
146
|
+
export { DatadogPresetConfig, DatadogSite, createDatadogConfig };
|
|
147
|
+
//# sourceMappingURL=datadog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"datadog.d.ts","names":[],"sources":["../src/datadog.ts"],"mappings":";;;;;;;KA0CY,WAAA;AA2JI;;;AAAA,UAhJC,mBAAA;;;;;;;;EAQf,MAAA;;;;;;;EAQA,IAAA,GAAO,WAAA;;;;;EAMP,OAAA;;;;;;;EAQA,WAAA;;;;;;;EAQA,OAAA;;;;;;;;;;;;;;;;;;;;;;EAuBA,UAAA;;;;;;;;;;;;;;EAeA,QAAA;;;;;;EAOA,SAAA;;;;;;EAOA,SAAA;;;;;EAMA,mBAAA,GAAsB,kBAAkB;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA8C1B,mBAAA,CACd,MAAA,EAAQ,mBAAA,GACP,aAAa"}
|
package/dist/datadog.js
CHANGED
|
@@ -1,113 +1,137 @@
|
|
|
1
|
-
import { createRequire } from
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
//#region src/datadog.ts
|
|
3
|
+
/**
|
|
4
|
+
* Datadog preset for autotel
|
|
5
|
+
*
|
|
6
|
+
* Provides a simplified configuration helper for Datadog integration
|
|
7
|
+
* with best practices built-in.
|
|
8
|
+
*
|
|
9
|
+
* @example Direct cloud ingestion (serverless, edge)
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { init } from 'autotel';
|
|
12
|
+
* import { createDatadogConfig } from 'autotel-backends/datadog';
|
|
13
|
+
*
|
|
14
|
+
* init(createDatadogConfig({
|
|
15
|
+
* apiKey: process.env.DATADOG_API_KEY!,
|
|
16
|
+
* service: 'my-lambda',
|
|
17
|
+
* enableLogs: true,
|
|
18
|
+
* }));
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @example Local Datadog Agent (long-running services, Kubernetes)
|
|
22
|
+
* ```typescript
|
|
23
|
+
* import { init } from 'autotel';
|
|
24
|
+
* import { createDatadogConfig } from 'autotel-backends/datadog';
|
|
25
|
+
*
|
|
26
|
+
* init(createDatadogConfig({
|
|
27
|
+
* service: 'my-api',
|
|
28
|
+
* useAgent: true, // No API key needed - Agent handles it
|
|
29
|
+
* }));
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
/**
|
|
33
|
+
* Create an autotel configuration optimized for Datadog.
|
|
34
|
+
*
|
|
35
|
+
* This preset handles:
|
|
36
|
+
* - Proper OTLP endpoint configuration (Agent vs direct ingestion)
|
|
37
|
+
* - Direct: https://otlp.{site} → SDK appends /v1/traces, /v1/metrics, /v1/logs
|
|
38
|
+
* - Agent: http://localhost:4318 (default)
|
|
39
|
+
* - Datadog API key authentication headers (direct ingestion only)
|
|
40
|
+
* - Unified service tagging (service, env, version)
|
|
41
|
+
* - Resource attribute best practices
|
|
42
|
+
* - Optional log export configuration
|
|
43
|
+
*
|
|
44
|
+
* @param config - Datadog-specific configuration options
|
|
45
|
+
* @returns AutotelConfig ready to pass to init()
|
|
46
|
+
*
|
|
47
|
+
* @example Simple cloud ingestion
|
|
48
|
+
* ```typescript
|
|
49
|
+
* init(createDatadogConfig({
|
|
50
|
+
* apiKey: process.env.DATADOG_API_KEY!,
|
|
51
|
+
* service: 'my-app',
|
|
52
|
+
* }));
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* @example With logs and custom environment
|
|
56
|
+
* ```typescript
|
|
57
|
+
* init(createDatadogConfig({
|
|
58
|
+
* apiKey: process.env.DATADOG_API_KEY!,
|
|
59
|
+
* service: 'my-app',
|
|
60
|
+
* environment: 'production',
|
|
61
|
+
* version: '2.1.0',
|
|
62
|
+
* enableLogs: true,
|
|
63
|
+
* }));
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* @example Using local Datadog Agent
|
|
67
|
+
* ```typescript
|
|
68
|
+
* init(createDatadogConfig({
|
|
69
|
+
* service: 'my-api',
|
|
70
|
+
* useAgent: true,
|
|
71
|
+
* agentHost: 'datadog-agent.default.svc.cluster.local', // Kubernetes
|
|
72
|
+
* }));
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
4
75
|
function createDatadogConfig(config) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
process.env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT = logsEndpoint;
|
|
63
|
-
}
|
|
64
|
-
if (!process.env.OTEL_EXPORTER_OTLP_LOGS_PROTOCOL) {
|
|
65
|
-
process.env.OTEL_EXPORTER_OTLP_LOGS_PROTOCOL = "http/protobuf";
|
|
66
|
-
}
|
|
67
|
-
if (!useAgent && apiKey && !process.env.OTEL_EXPORTER_OTLP_LOGS_HEADERS) {
|
|
68
|
-
process.env.OTEL_EXPORTER_OTLP_LOGS_HEADERS = `dd-api-key=${apiKey}`;
|
|
69
|
-
}
|
|
70
|
-
const resourceAttrs = [
|
|
71
|
-
`service.name=${service}`,
|
|
72
|
-
environment ? `deployment.environment=${environment}` : null,
|
|
73
|
-
version ? `service.version=${version}` : null
|
|
74
|
-
].filter(Boolean).join(",");
|
|
75
|
-
if (!process.env.OTEL_RESOURCE_ATTRIBUTES) {
|
|
76
|
-
process.env.OTEL_RESOURCE_ATTRIBUTES = resourceAttrs;
|
|
77
|
-
}
|
|
78
|
-
if (logRecordProcessors) {
|
|
79
|
-
cloudConfig.logRecordProcessors = logRecordProcessors;
|
|
80
|
-
} else {
|
|
81
|
-
try {
|
|
82
|
-
const pkgRequire = createRequire(
|
|
83
|
-
typeof __filename === "string" ? __filename : import.meta.url
|
|
84
|
-
);
|
|
85
|
-
const { BatchLogRecordProcessor } = pkgRequire(
|
|
86
|
-
"@opentelemetry/sdk-logs"
|
|
87
|
-
);
|
|
88
|
-
const { OTLPLogExporter } = pkgRequire(
|
|
89
|
-
"@opentelemetry/exporter-logs-otlp-http"
|
|
90
|
-
);
|
|
91
|
-
cloudConfig.logRecordProcessors = [
|
|
92
|
-
new BatchLogRecordProcessor(
|
|
93
|
-
new OTLPLogExporter({
|
|
94
|
-
url: `${otlpEndpoint}/v1/logs`,
|
|
95
|
-
headers: {
|
|
96
|
-
"dd-api-key": apiKey
|
|
97
|
-
}
|
|
98
|
-
})
|
|
99
|
-
)
|
|
100
|
-
];
|
|
101
|
-
} catch {
|
|
102
|
-
throw new Error(
|
|
103
|
-
"Log export requires @opentelemetry/sdk-logs and @opentelemetry/exporter-logs-otlp-http. Install them or set enableLogs: false."
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
return cloudConfig;
|
|
76
|
+
const { apiKey, site = "datadoghq.com", service, environment, version, enableLogs = false, useAgent = false, agentHost = "localhost", agentPort = 4318, logRecordProcessors } = config;
|
|
77
|
+
if (!useAgent && !apiKey) throw new Error("Datadog API key is required for direct cloud ingestion. Either provide apiKey or set useAgent: true to use local Datadog Agent.");
|
|
78
|
+
const baseConfig = {
|
|
79
|
+
service,
|
|
80
|
+
environment,
|
|
81
|
+
version
|
|
82
|
+
};
|
|
83
|
+
if (useAgent) {
|
|
84
|
+
const agentEndpoint = `http://${agentHost}:${agentPort}`;
|
|
85
|
+
if (enableLogs) {
|
|
86
|
+
const logsEndpoint = `http://${agentHost}:${agentPort}/v1/logs`;
|
|
87
|
+
if (!process.env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT) process.env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT = logsEndpoint;
|
|
88
|
+
if (!process.env.OTEL_EXPORTER_OTLP_LOGS_PROTOCOL) process.env.OTEL_EXPORTER_OTLP_LOGS_PROTOCOL = "http/protobuf";
|
|
89
|
+
const resourceAttrs = [
|
|
90
|
+
`service.name=${service}`,
|
|
91
|
+
environment ? `deployment.environment=${environment}` : null,
|
|
92
|
+
version ? `service.version=${version}` : null
|
|
93
|
+
].filter(Boolean).join(",");
|
|
94
|
+
if (!process.env.OTEL_RESOURCE_ATTRIBUTES) process.env.OTEL_RESOURCE_ATTRIBUTES = resourceAttrs;
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
...baseConfig,
|
|
98
|
+
endpoint: agentEndpoint
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
const otlpEndpoint = `https://otlp.${site}`;
|
|
102
|
+
const authHeaders = `dd-api-key=${apiKey}`;
|
|
103
|
+
const cloudConfig = {
|
|
104
|
+
...baseConfig,
|
|
105
|
+
endpoint: otlpEndpoint,
|
|
106
|
+
headers: authHeaders
|
|
107
|
+
};
|
|
108
|
+
if (enableLogs) {
|
|
109
|
+
const logsEndpoint = useAgent ? `http://${agentHost}:${agentPort}/v1/logs` : `https://otlp.${site}/v1/logs`;
|
|
110
|
+
if (!process.env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT) process.env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT = logsEndpoint;
|
|
111
|
+
if (!process.env.OTEL_EXPORTER_OTLP_LOGS_PROTOCOL) process.env.OTEL_EXPORTER_OTLP_LOGS_PROTOCOL = "http/protobuf";
|
|
112
|
+
if (!useAgent && apiKey && !process.env.OTEL_EXPORTER_OTLP_LOGS_HEADERS) process.env.OTEL_EXPORTER_OTLP_LOGS_HEADERS = `dd-api-key=${apiKey}`;
|
|
113
|
+
const resourceAttrs = [
|
|
114
|
+
`service.name=${service}`,
|
|
115
|
+
environment ? `deployment.environment=${environment}` : null,
|
|
116
|
+
version ? `service.version=${version}` : null
|
|
117
|
+
].filter(Boolean).join(",");
|
|
118
|
+
if (!process.env.OTEL_RESOURCE_ATTRIBUTES) process.env.OTEL_RESOURCE_ATTRIBUTES = resourceAttrs;
|
|
119
|
+
if (logRecordProcessors) cloudConfig.logRecordProcessors = logRecordProcessors;
|
|
120
|
+
else try {
|
|
121
|
+
const pkgRequire = createRequire(typeof __filename === "string" ? __filename : import.meta.url);
|
|
122
|
+
const { BatchLogRecordProcessor } = pkgRequire("@opentelemetry/sdk-logs");
|
|
123
|
+
const { OTLPLogExporter } = pkgRequire("@opentelemetry/exporter-logs-otlp-http");
|
|
124
|
+
cloudConfig.logRecordProcessors = [new BatchLogRecordProcessor(new OTLPLogExporter({
|
|
125
|
+
url: `${otlpEndpoint}/v1/logs`,
|
|
126
|
+
headers: { "dd-api-key": apiKey }
|
|
127
|
+
}))];
|
|
128
|
+
} catch {
|
|
129
|
+
throw new Error("Log export requires @opentelemetry/sdk-logs and @opentelemetry/exporter-logs-otlp-http. Install them or set enableLogs: false.");
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return cloudConfig;
|
|
109
133
|
}
|
|
110
|
-
|
|
134
|
+
//#endregion
|
|
111
135
|
export { createDatadogConfig };
|
|
112
|
-
|
|
136
|
+
|
|
113
137
|
//# sourceMappingURL=datadog.js.map
|
package/dist/datadog.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/datadog.ts"],"names":[],"mappings":";;;AAmMO,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;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QAAA,MAAM,UAAA,GAAa,aAAA;AAAA,UACjB,OAAO,UAAA,KAAe,QAAA,GAAW,UAAA,GAAa,MAAA,CAAA,IAAA,CAAY;AAAA,SAC5D;AACA,QAAA,MAAM,EAAE,yBAAwB,GAAI,UAAA;AAAA,UAClC;AAAA,SACF;AACA,QAAA,MAAM,EAAE,iBAAgB,GAAI,UAAA;AAAA,UAC1B;AAAA,SACF;AAEA,QAAA,WAAA,CAAY,mBAAA,GAAsB;AAAA,UAChC,IAAI,uBAAA;AAAA,YACF,IAAI,eAAA,CAAgB;AAAA,cAClB,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// `__filename` exists under CJS (including esbuild's CJS output wrapper) but\n// not pure ESM. `typeof` is safe against an undeclared identifier and lets\n// the conditional pick the working URL in either format.\ndeclare const __filename: string | undefined;\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 *\n * When enabled, this:\n * 1. Sets up OTel Logs SDK with OTLP exporter (for direct OTel logs API usage)\n * 2. Auto-configures OTEL_EXPORTER_OTLP_LOGS_* env vars for pino-opentelemetry-transport\n *\n * For Pino users: Just add pino-opentelemetry-transport to your logger config:\n * ```typescript\n * const logger = pino({\n * transport: {\n * targets: [\n * { target: 'pino-pretty' },\n * { target: 'pino-opentelemetry-transport' }, // Auto-configured!\n * ],\n * },\n * });\n * ```\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 // Auto-configure env vars for pino-opentelemetry-transport in agent mode\n if (enableLogs) {\n const logsEndpoint = `http://${agentHost}:${agentPort}/v1/logs`;\n\n if (!process.env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT) {\n process.env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT = logsEndpoint;\n }\n\n if (!process.env.OTEL_EXPORTER_OTLP_LOGS_PROTOCOL) {\n process.env.OTEL_EXPORTER_OTLP_LOGS_PROTOCOL = 'http/protobuf';\n }\n\n // No API key header needed for agent mode - Agent handles authentication\n\n const resourceAttrs = [\n `service.name=${service}`,\n environment ? `deployment.environment=${environment}` : null,\n version ? `service.version=${version}` : null,\n ]\n .filter(Boolean)\n .join(',');\n\n if (!process.env.OTEL_RESOURCE_ATTRIBUTES) {\n process.env.OTEL_RESOURCE_ATTRIBUTES = resourceAttrs;\n }\n }\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 headers: authHeaders,\n };\n\n // Add log export if enabled\n if (enableLogs) {\n // Auto-configure env vars for pino-opentelemetry-transport and other OTel log transports\n // These are read by pino-opentelemetry-transport, otlp-logger, and similar libraries\n const logsEndpoint = useAgent\n ? `http://${agentHost}:${agentPort}/v1/logs`\n : `https://otlp.${site}/v1/logs`;\n\n // Only set if not already configured (allow user override)\n if (!process.env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT) {\n process.env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT = logsEndpoint;\n }\n\n if (!process.env.OTEL_EXPORTER_OTLP_LOGS_PROTOCOL) {\n process.env.OTEL_EXPORTER_OTLP_LOGS_PROTOCOL = 'http/protobuf';\n }\n\n // Only set API key header for direct cloud ingestion (not agent mode)\n if (!useAgent && apiKey && !process.env.OTEL_EXPORTER_OTLP_LOGS_HEADERS) {\n process.env.OTEL_EXPORTER_OTLP_LOGS_HEADERS = `dd-api-key=${apiKey}`;\n }\n\n // Set resource attributes for service identification\n const resourceAttrs = [\n `service.name=${service}`,\n environment ? `deployment.environment=${environment}` : null,\n version ? `service.version=${version}` : null,\n ]\n .filter(Boolean)\n .join(',');\n\n if (!process.env.OTEL_RESOURCE_ATTRIBUTES) {\n process.env.OTEL_RESOURCE_ATTRIBUTES = resourceAttrs;\n }\n\n if (logRecordProcessors) {\n // Use custom processors if provided\n cloudConfig.logRecordProcessors = logRecordProcessors;\n } else {\n // Create default OTLP log exporter\n try {\n const pkgRequire = createRequire(\n typeof __filename === 'string' ? __filename : import.meta.url,\n );\n const { BatchLogRecordProcessor } = pkgRequire(\n '@opentelemetry/sdk-logs',\n );\n const { OTLPLogExporter } = pkgRequire(\n '@opentelemetry/exporter-logs-otlp-http',\n );\n\n cloudConfig.logRecordProcessors = [\n new BatchLogRecordProcessor(\n new OTLPLogExporter({\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 @opentelemetry/sdk-logs and @opentelemetry/exporter-logs-otlp-http. ' +\n 'Install them or set enableLogs: false.',\n );\n }\n }\n }\n\n return cloudConfig;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"datadog.js","names":[],"sources":["../src/datadog.ts"],"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// `__filename` exists under CJS (including esbuild's CJS output wrapper) but\n// not pure ESM. `typeof` is safe against an undeclared identifier and lets\n// the conditional pick the working URL in either format.\ndeclare const __filename: string | undefined;\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 *\n * When enabled, this:\n * 1. Sets up OTel Logs SDK with OTLP exporter (for direct OTel logs API usage)\n * 2. Auto-configures OTEL_EXPORTER_OTLP_LOGS_* env vars for pino-opentelemetry-transport\n *\n * For Pino users: Just add pino-opentelemetry-transport to your logger config:\n * ```typescript\n * const logger = pino({\n * transport: {\n * targets: [\n * { target: 'pino-pretty' },\n * { target: 'pino-opentelemetry-transport' }, // Auto-configured!\n * ],\n * },\n * });\n * ```\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 // Auto-configure env vars for pino-opentelemetry-transport in agent mode\n if (enableLogs) {\n const logsEndpoint = `http://${agentHost}:${agentPort}/v1/logs`;\n\n if (!process.env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT) {\n process.env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT = logsEndpoint;\n }\n\n if (!process.env.OTEL_EXPORTER_OTLP_LOGS_PROTOCOL) {\n process.env.OTEL_EXPORTER_OTLP_LOGS_PROTOCOL = 'http/protobuf';\n }\n\n // No API key header needed for agent mode - Agent handles authentication\n\n const resourceAttrs = [\n `service.name=${service}`,\n environment ? `deployment.environment=${environment}` : null,\n version ? `service.version=${version}` : null,\n ]\n .filter(Boolean)\n .join(',');\n\n if (!process.env.OTEL_RESOURCE_ATTRIBUTES) {\n process.env.OTEL_RESOURCE_ATTRIBUTES = resourceAttrs;\n }\n }\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 headers: authHeaders,\n };\n\n // Add log export if enabled\n if (enableLogs) {\n // Auto-configure env vars for pino-opentelemetry-transport and other OTel log transports\n // These are read by pino-opentelemetry-transport, otlp-logger, and similar libraries\n const logsEndpoint = useAgent\n ? `http://${agentHost}:${agentPort}/v1/logs`\n : `https://otlp.${site}/v1/logs`;\n\n // Only set if not already configured (allow user override)\n if (!process.env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT) {\n process.env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT = logsEndpoint;\n }\n\n if (!process.env.OTEL_EXPORTER_OTLP_LOGS_PROTOCOL) {\n process.env.OTEL_EXPORTER_OTLP_LOGS_PROTOCOL = 'http/protobuf';\n }\n\n // Only set API key header for direct cloud ingestion (not agent mode)\n if (!useAgent && apiKey && !process.env.OTEL_EXPORTER_OTLP_LOGS_HEADERS) {\n process.env.OTEL_EXPORTER_OTLP_LOGS_HEADERS = `dd-api-key=${apiKey}`;\n }\n\n // Set resource attributes for service identification\n const resourceAttrs = [\n `service.name=${service}`,\n environment ? `deployment.environment=${environment}` : null,\n version ? `service.version=${version}` : null,\n ]\n .filter(Boolean)\n .join(',');\n\n if (!process.env.OTEL_RESOURCE_ATTRIBUTES) {\n process.env.OTEL_RESOURCE_ATTRIBUTES = resourceAttrs;\n }\n\n if (logRecordProcessors) {\n // Use custom processors if provided\n cloudConfig.logRecordProcessors = logRecordProcessors;\n } else {\n // Create default OTLP log exporter\n try {\n const pkgRequire = createRequire(\n typeof __filename === 'string' ? __filename : import.meta.url,\n );\n const { BatchLogRecordProcessor } = pkgRequire(\n '@opentelemetry/sdk-logs',\n );\n const { OTLPLogExporter } = pkgRequire(\n '@opentelemetry/exporter-logs-otlp-http',\n );\n\n cloudConfig.logRecordProcessors = [\n new BatchLogRecordProcessor(\n new OTLPLogExporter({\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 @opentelemetry/sdk-logs and @opentelemetry/exporter-logs-otlp-http. ' +\n 'Install them or set enableLogs: false.',\n );\n }\n }\n }\n\n return cloudConfig;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmMA,SAAgB,oBACd,QACe;CACf,MAAM,EACJ,QACA,OAAO,iBACP,SACA,aACA,SACA,aAAa,OACb,WAAW,OACX,YAAY,aACZ,YAAY,MACZ,wBACE;CAGJ,IAAI,CAAC,YAAY,CAAC,QAChB,MAAM,IAAI,MACR,iIAEF;CAGF,MAAM,aAA4B;EAChC;EACA;EACA;CACF;CAGA,IAAI,UAAU;EACZ,MAAM,gBAAgB,UAAU,UAAU,GAAG;EAG7C,IAAI,YAAY;GACd,MAAM,eAAe,UAAU,UAAU,GAAG,UAAU;GAEtD,IAAI,CAAC,QAAQ,IAAI,kCACf,QAAQ,IAAI,mCAAmC;GAGjD,IAAI,CAAC,QAAQ,IAAI,kCACf,QAAQ,IAAI,mCAAmC;GAKjD,MAAM,gBAAgB;IACpB,gBAAgB;IAChB,cAAc,0BAA0B,gBAAgB;IACxD,UAAU,mBAAmB,YAAY;GAC3C,CAAC,CACE,OAAO,OAAO,CAAC,CACf,KAAK,GAAG;GAEX,IAAI,CAAC,QAAQ,IAAI,0BACf,QAAQ,IAAI,2BAA2B;EAE3C;EAEA,OAAO;GACL,GAAG;GACH,UAAU;EAEZ;CACF;CAIA,MAAM,eAAe,gBAAgB;CACrC,MAAM,cAAc,cAAc;CAElC,MAAM,cAA6B;EACjC,GAAG;EACH,UAAU;EACV,SAAS;CACX;CAGA,IAAI,YAAY;E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