-
Notifications
You must be signed in to change notification settings - Fork 4
/
OTLPExporterFastlyBackendBase.ts
53 lines (44 loc) · 1.36 KB
/
OTLPExporterFastlyBackendBase.ts
1
2
3
4
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
/*
* Copyright Fastly, Inc.
* Licensed under the MIT license. See LICENSE file for details.
*/
import { baggageUtils, getEnv } from '@opentelemetry/core';
import { parseHeaders } from '@opentelemetry/otlp-exporter-base';
import { OTLPExporterFastlyBase } from './OTLPExporterFastlyBase.js';
import { CompressionAlgorithm, OTLPExporterFastlyBackendConfigBase } from './types.js';
import { configureCompression, sendWithFetch } from './util.js';
/**
* Collector Metric Exporter abstract base class for Fastly backend
*/
export abstract class OTLPExporterFastlyBackendBase<
ExportItem,
ServiceRequest,
> extends OTLPExporterFastlyBase<
OTLPExporterFastlyBackendConfigBase,
ExportItem,
ServiceRequest
> {
DEFAULT_HEADERS: Record<string, string> = {};
headers: Record<string, string>;
backend: string;
compression: CompressionAlgorithm;
protected constructor(config: OTLPExporterFastlyBackendConfigBase) {
super(config);
this.headers = Object.assign(
this.DEFAULT_HEADERS,
parseHeaders(config.headers),
baggageUtils.parseKeyPairsIntoRecord(getEnv().OTEL_EXPORTER_OTLP_HEADERS)
);
this.backend = config.backend;
this.compression = configureCompression(config.compression);
}
override _send(
body: string,
): Promise<void> {
return sendWithFetch(
this,
body,
'application/json'
);
}
}