otlp-logger 1.1.1 → 1.1.2
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/README.md +15 -9
- package/lib/create-log-processor.js +1 -14
- package/lib/otlp-logger.js +8 -4
- package/package.json +10 -11
- package/types/create-log-processor.d.ts +9 -2
- package/types/create-log-processor.d.ts.map +1 -1
- package/types/otlp-logger.d.ts.map +1 -1
- package/lib/multi-log-processor.js +0 -38
- package/types/multi-log-processor.d.ts +0 -13
- package/types/multi-log-processor.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# otlp-logger
|
|
2
|
+
|
|
2
3
|
[](https://www.npmjs.com/package/otlp-logger)
|
|
3
4
|
[](https://standardjs.com/)
|
|
4
5
|
|
|
@@ -6,15 +7,17 @@ Sends logs in the [OpenTelemetry Log Data Model](https://github.com/open-telemet
|
|
|
6
7
|
|
|
7
8
|
## Install
|
|
8
9
|
|
|
9
|
-
```
|
|
10
|
+
```bash
|
|
10
11
|
npm i otlp-logger
|
|
11
12
|
```
|
|
12
13
|
|
|
13
14
|
## Configuration
|
|
15
|
+
|
|
14
16
|
### Protocol
|
|
15
|
-
can be set to `http/protobuf`, `grpc`, `http` or `console` by using
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
can be set to `http/protobuf`, `grpc`, `http` or `console` by using
|
|
19
|
+
|
|
20
|
+
* env var `OTEL_EXPORTER_OTLP_PROTOCOL`
|
|
18
21
|
* env var `OTEL_EXPORTER_OTLP_LOGS_PROTOCOL`
|
|
19
22
|
* setting the exporterProtocol option
|
|
20
23
|
|
|
@@ -33,27 +36,30 @@ Set either of the following environment variables:
|
|
|
33
36
|
#### Protocol-specific exporter configuration
|
|
34
37
|
|
|
35
38
|
#### `http/protobuf`
|
|
39
|
+
|
|
36
40
|
[Env vars in README](https://github.com/open-telemetry/opentelemetry-js/blob/d4a41bd815dd50703f692000a70c59235ad71959/experimental/packages/exporter-trace-otlp-proto/README.md#exporter-timeout-configuration)
|
|
37
41
|
|
|
38
42
|
#### `grpc`
|
|
43
|
+
|
|
39
44
|
[Environment Variable Configuration](https://github.com/open-telemetry/opentelemetry-js/blob/d4a41bd815dd50703f692000a70c59235ad71959/experimental/packages/exporter-logs-otlp-grpc/README.md#environment-variable-configuration)
|
|
40
45
|
|
|
41
46
|
#### `http`
|
|
42
|
-
[Env vars in README](https://github.com/open-telemetry/opentelemetry-js/blob/d4a41bd815dd50703f692000a70c59235ad71959/experimental/packages/exporter-trace-otlp-http/README.md#configuration-options-as-environment-variables)
|
|
43
47
|
|
|
48
|
+
[Env vars in README](https://github.com/open-telemetry/opentelemetry-js/blob/d4a41bd815dd50703f692000a70c59235ad71959/experimental/packages/exporter-trace-otlp-http/README.md#configuration-options-as-environment-variables)
|
|
44
49
|
|
|
45
50
|
#### Processor-specific configuration
|
|
51
|
+
|
|
46
52
|
If batch log processor is selected (is default), it can be configured using env vars described in the [OpenTelemetry specification](https://opentelemetry.io/docs/specs/otel/configuration/sdk-environment-variables/#batch-logrecord-processor)
|
|
47
53
|
|
|
48
54
|
### Options
|
|
55
|
+
|
|
49
56
|
When using the transport, the following options can be used to configure the transport programmatically:
|
|
50
57
|
|
|
51
58
|
* `loggerName`: name to be used by the OpenTelemetry logger
|
|
52
|
-
* `serviceVersion`:
|
|
59
|
+
* `serviceVersion`: version to be used by the OpenTelemetry logger
|
|
53
60
|
* `resourceAttributes`: Object containing [resource attributes](https://opentelemetry.io/docs/instrumentation/js/resources/). Optional
|
|
54
61
|
* `logRecordProcessorOptions`: a single object or an array of objects specifying the LogProcessor and LogExporter types and constructor params. Optional
|
|
55
62
|
|
|
56
|
-
|
|
57
63
|
## Usage
|
|
58
64
|
|
|
59
65
|
### Minimalistic example
|
|
@@ -62,7 +68,7 @@ Make sure you have access to an OTEL collector.
|
|
|
62
68
|
|
|
63
69
|
To start quickly, create a minimal configuration for OTEL collector in the `otel-collector-config.yaml` file:
|
|
64
70
|
|
|
65
|
-
```
|
|
71
|
+
```yaml
|
|
66
72
|
receivers:
|
|
67
73
|
otlp:
|
|
68
74
|
protocols:
|
|
@@ -89,7 +95,7 @@ service:
|
|
|
89
95
|
|
|
90
96
|
The collector can then be ran with:
|
|
91
97
|
|
|
92
|
-
```
|
|
98
|
+
```bash
|
|
93
99
|
docker run --volume=$(pwd)/otel-collector-config.yaml:/etc/otel-collector-config.yaml:rw --volume=/tmp/test-logs:/etc/test-logs:rw -p 4317:4317 -d otel/opentelemetry-collector-contrib:latest --config=/etc/otel-collector-config.yaml
|
|
94
100
|
```
|
|
95
101
|
|
|
@@ -113,7 +119,7 @@ logger.emit({
|
|
|
113
119
|
|
|
114
120
|
Run the service setting the `OTEL_EXPORTER_OTLP_LOGS_ENDPOINT` and `OTEL_RESOURCE_ATTRIBUTES` env vars
|
|
115
121
|
|
|
116
|
-
```
|
|
122
|
+
```bash
|
|
117
123
|
OTEL_EXPORTER_OTLP_LOGS_PROTOCOL='grpc' OTEL_EXPORTER_OTLP_LOGS_ENDPOINT=http://localhost:4317 OTEL_RESOURCE_ATTRIBUTES="service.name=my-service,service.version=1.2.3" node index.js
|
|
118
124
|
```
|
|
119
125
|
|
|
@@ -6,19 +6,6 @@ const {
|
|
|
6
6
|
ConsoleLogRecordExporter
|
|
7
7
|
} = require('@opentelemetry/sdk-logs')
|
|
8
8
|
|
|
9
|
-
const { MultiLogRecordProcessor } = require('./multi-log-processor')
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @param {LogRecordProcessorOptions | LogRecordProcessorOptions[]} [logRecordProcessorOptions]
|
|
13
|
-
*/
|
|
14
|
-
function createLogProcessor (logRecordProcessorOptions) {
|
|
15
|
-
return Array.isArray(logRecordProcessorOptions)
|
|
16
|
-
? new MultiLogRecordProcessor(
|
|
17
|
-
logRecordProcessorOptions.map(createLogRecordProcessor)
|
|
18
|
-
)
|
|
19
|
-
: createLogRecordProcessor(logRecordProcessorOptions)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
9
|
/**
|
|
23
10
|
* @typedef {"batch" | "simple"} RecordProcessorType
|
|
24
11
|
* @typedef {Object} LogRecordProcessorOptions
|
|
@@ -29,7 +16,7 @@ function createLogProcessor (logRecordProcessorOptions) {
|
|
|
29
16
|
* @param {LogRecordProcessorOptions} [opts]
|
|
30
17
|
* @returns {import('@opentelemetry/sdk-logs').LogRecordProcessor}
|
|
31
18
|
*/
|
|
32
|
-
function
|
|
19
|
+
function createLogProcessor (opts) {
|
|
33
20
|
const exporter = createExporter(opts?.exporterOptions)
|
|
34
21
|
|
|
35
22
|
if (opts?.recordProcessorType === 'simple') {
|
package/lib/otlp-logger.js
CHANGED
|
@@ -37,13 +37,17 @@ function getOtlpLogger (opts) {
|
|
|
37
37
|
)
|
|
38
38
|
})
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
const logRecordProcessorOptionsArray = Array.isArray(opts.logRecordProcessorOptions) ? opts.logRecordProcessorOptions : [opts.logRecordProcessorOptions]
|
|
41
|
+
|
|
42
|
+
logRecordProcessorOptionsArray.forEach(logRecordProcessorOptions => {
|
|
43
|
+
loggerProvider.addLogRecordProcessor(
|
|
44
|
+
createLogProcessor(logRecordProcessorOptions)
|
|
45
|
+
)
|
|
46
|
+
})
|
|
43
47
|
|
|
44
48
|
logs.setGlobalLoggerProvider(loggerProvider)
|
|
45
49
|
|
|
46
|
-
const logger =
|
|
50
|
+
const logger = loggerProvider.getLogger(opts.loggerName, opts.serviceVersion)
|
|
47
51
|
|
|
48
52
|
return {
|
|
49
53
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "otlp-logger",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "Exports logs to OpenTelemetry Collector using OTLP protocol",
|
|
5
5
|
"main": "lib/otlp-logger.js",
|
|
6
6
|
"scripts": {
|
|
@@ -17,21 +17,20 @@
|
|
|
17
17
|
"repository": "github:Vunovati/otlp-logger",
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@opentelemetry/api-logs": "^0.
|
|
21
|
-
"@opentelemetry/
|
|
22
|
-
"@opentelemetry/exporter-logs-otlp-
|
|
23
|
-
"@opentelemetry/exporter-logs-otlp-
|
|
24
|
-
"@opentelemetry/exporter-logs-otlp-proto": "^0.48.0",
|
|
20
|
+
"@opentelemetry/api-logs": "^0.49.1",
|
|
21
|
+
"@opentelemetry/exporter-logs-otlp-grpc": "^0.49.1",
|
|
22
|
+
"@opentelemetry/exporter-logs-otlp-http": "^0.49.1",
|
|
23
|
+
"@opentelemetry/exporter-logs-otlp-proto": "^0.49.1",
|
|
25
24
|
"@opentelemetry/resources": "^1.17.0",
|
|
26
|
-
"@opentelemetry/sdk-logs": "^0.
|
|
25
|
+
"@opentelemetry/sdk-logs": "^0.49.1"
|
|
27
26
|
},
|
|
28
27
|
"types": "./types/otlp-logger.d.ts",
|
|
29
28
|
"devDependencies": {
|
|
30
|
-
"@commitlint/cli": "^
|
|
31
|
-
"@commitlint/config-conventional": "^
|
|
29
|
+
"@commitlint/cli": "^19.0.3",
|
|
30
|
+
"@commitlint/config-conventional": "^19.0.3",
|
|
32
31
|
"@opentelemetry/api": "^1.4.1",
|
|
33
|
-
"@opentelemetry/instrumentation-http": "^0.
|
|
34
|
-
"@opentelemetry/sdk-node": "^0.
|
|
32
|
+
"@opentelemetry/instrumentation-http": "^0.49.1",
|
|
33
|
+
"@opentelemetry/sdk-node": "^0.49.1",
|
|
35
34
|
"@tapjs/sinon": "^1.1.16",
|
|
36
35
|
"@types/node": "^20.8.2",
|
|
37
36
|
"husky": "^9.0.10",
|
|
@@ -24,7 +24,14 @@ export type ConsoleExporterOptions = {
|
|
|
24
24
|
};
|
|
25
25
|
export type ExporterOptions = GrpcExporterOptions | HttpExporterOptions | ProtobufExporterOptions | ConsoleExporterOptions;
|
|
26
26
|
/**
|
|
27
|
-
* @
|
|
27
|
+
* @typedef {"batch" | "simple"} RecordProcessorType
|
|
28
|
+
* @typedef {Object} LogRecordProcessorOptions
|
|
29
|
+
* @property {RecordProcessorType} recordProcessorType = "batch"
|
|
30
|
+
* @property {ExporterOptions} [exporterOptions]
|
|
31
|
+
* @property {import('@opentelemetry/sdk-logs').BufferConfig} [processorConfig]
|
|
32
|
+
*
|
|
33
|
+
* @param {LogRecordProcessorOptions} [opts]
|
|
34
|
+
* @returns {import('@opentelemetry/sdk-logs').LogRecordProcessor}
|
|
28
35
|
*/
|
|
29
|
-
export function createLogProcessor(
|
|
36
|
+
export function createLogProcessor(opts?: LogRecordProcessorOptions): import('@opentelemetry/sdk-logs').LogRecordProcessor;
|
|
30
37
|
//# sourceMappingURL=create-log-processor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-log-processor.d.ts","sourceRoot":"","sources":["../lib/create-log-processor.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"create-log-processor.d.ts","sourceRoot":"","sources":["../lib/create-log-processor.js"],"names":[],"mappings":"kCASa,OAAO,GAAG,QAAQ;;;;;yBAEjB,mBAAmB;sBACnB,eAAe;sBACf,OAAO,yBAAyB,EAAE,YAAY;;;cAiB9C,MAAM;0BACN,OAAO,wCAAwC,EAAE,0BAA0B;;;cAG3E,MAAM;0BACN,OAAO,mCAAmC,EAAE,0BAA0B;;;cAGtE,eAAe;8BACf,OAAO,mCAAmC,EAAE,0BAA0B;;;cAGtE,SAAS;;8BAEV,mBAAmB,GAAG,mBAAmB,GAAG,uBAAuB,GAAG,sBAAsB;AApCzG;;;;;;;;;GASG;AACH,0CAHW,yBAAyB,GACvB,OAAO,yBAAyB,EAAE,kBAAkB,CAUhE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"otlp-logger.d.ts","sourceRoot":"","sources":["../lib/otlp-logger.js"],"names":[],"mappings":";gBAiBc,MAAM;oBACN,MAAM;gCACN,OAAO,wBAAwB,EAAE,yBAAyB,GAAG,OAAO,wBAAwB,EAAE,yBAAyB,EAAE;;;AAJvI;;;;;;;;GAQG;AACH,oCAFW,OAAO;
|
|
1
|
+
{"version":3,"file":"otlp-logger.d.ts","sourceRoot":"","sources":["../lib/otlp-logger.js"],"names":[],"mappings":";gBAiBc,MAAM;oBACN,MAAM;gCACN,OAAO,wBAAwB,EAAE,yBAAyB,GAAG,OAAO,wBAAwB,EAAE,yBAAyB,EAAE;;;AAJvI;;;;;;;;GAQG;AACH,oCAFW,OAAO;IA8Bd;;OAEG;cADQ,OAAO,yBAAyB,EAAE,SAAS;;EASzD"}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
'use_strict'
|
|
2
|
-
|
|
3
|
-
const { callWithTimeout } = require('@opentelemetry/core')
|
|
4
|
-
|
|
5
|
-
// taken from https://github.com/open-telemetry/opentelemetry-js/blob/5fcd8cf136e2235903dde3df9ba03ced594f0e95/experimental/packages/sdk-logs/src/types.ts#L27C3-L27C26
|
|
6
|
-
const FORCE_FLUSH_TIMEOUT_MILLIS = 30000
|
|
7
|
-
/**
|
|
8
|
-
* Using the MultiLogRecordProcessor from the sdk-logs package is currently not possible because it is not exported.
|
|
9
|
-
* This should work as a drop-in replacement.
|
|
10
|
-
*/
|
|
11
|
-
class MultiLogRecordProcessor {
|
|
12
|
-
constructor (processors, forceFlushTimeoutMillis) {
|
|
13
|
-
this.processors = processors
|
|
14
|
-
this.forceFlushTimeoutMillis = forceFlushTimeoutMillis
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
async forceFlush () {
|
|
18
|
-
const timeout = this.forceFlushTimeoutMillis
|
|
19
|
-
await Promise.all(
|
|
20
|
-
this.processors.map(processor =>
|
|
21
|
-
(FORCE_FLUSH_TIMEOUT_MILLIS, callWithTimeout)(
|
|
22
|
-
processor.forceFlush(),
|
|
23
|
-
timeout
|
|
24
|
-
)
|
|
25
|
-
)
|
|
26
|
-
)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
onEmit (logRecord) {
|
|
30
|
-
this.processors.forEach(processors => processors.onEmit(logRecord))
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
async shutdown () {
|
|
34
|
-
await Promise.all(this.processors.map(processor => processor.shutdown()))
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
exports.MultiLogRecordProcessor = MultiLogRecordProcessor
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Using the MultiLogRecordProcessor from the sdk-logs package is currently not possible because it is not exported.
|
|
3
|
-
* This should work as a drop-in replacement.
|
|
4
|
-
*/
|
|
5
|
-
export class MultiLogRecordProcessor {
|
|
6
|
-
constructor(processors: any, forceFlushTimeoutMillis: any);
|
|
7
|
-
processors: any;
|
|
8
|
-
forceFlushTimeoutMillis: any;
|
|
9
|
-
forceFlush(): Promise<void>;
|
|
10
|
-
onEmit(logRecord: any): void;
|
|
11
|
-
shutdown(): Promise<void>;
|
|
12
|
-
}
|
|
13
|
-
//# sourceMappingURL=multi-log-processor.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"multi-log-processor.d.ts","sourceRoot":"","sources":["../lib/multi-log-processor.js"],"names":[],"mappings":"AAMA;;;GAGG;AACH;IACE,2DAGC;IAFC,gBAA4B;IAC5B,6BAAsD;IAGxD,4BAUC;IAED,6BAEC;IAED,0BAEC;CACF"}
|