pino-opentelemetry-transport
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -29,3 +29,2 @@ 'use strict' | ||
* @property {boolean} [useBatchProcessor=true] | ||
* @property {boolean} [debugOtlp=false] | ||
* @property {string} [messageKey="msg"] | ||
@@ -32,0 +31,0 @@ * |
{ | ||
"name": "pino-opentelemetry-transport", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "OpenTelemetry transport for Pino", | ||
@@ -16,2 +16,3 @@ "main": "pino-opentelemetry-transport.js", | ||
"author": "Vladimir Adamic <vladimir.adamic@nearform.com>", | ||
"repository": "github:Vunovati/pino-opentelemetry-transport", | ||
"license": "MIT", | ||
@@ -29,3 +30,2 @@ "dependencies": { | ||
"pino": "^8.14.1", | ||
"pino-pretty": "^7.6.0", | ||
"require-inject": "^1.4.4", | ||
@@ -32,0 +32,0 @@ "snazzy": "^9.0.0", |
@@ -14,6 +14,7 @@ 'use strict' | ||
* @property {string} loggerName | ||
* @property {string} serviceName | ||
* @property {string} serviceVersion | ||
* @property {boolean} includeTraceContext | ||
* @property {Object} [resourceAttributes={}] | ||
* @property {boolean} [useBatchProcessor=true] | ||
* @property {string} [messageKey="msg"] | ||
* @property {import('@opentelemetry/sdk-logs').LogRecordExporter} [logRecordExporter] | ||
* | ||
@@ -24,4 +25,4 @@ * @param {Options} opts | ||
const logger = getOtlpLogger({ | ||
...opts, | ||
logRecordExporter: new OTLPLogExporter() | ||
logRecordExporter: new OTLPLogExporter(), | ||
...opts | ||
}) | ||
@@ -28,0 +29,0 @@ |
@@ -8,3 +8,3 @@ # pino-opentelemetry-transport | ||
Pino transport for OpenTelemetry. Outputs logs in the [OpenTelemetry Log Data Model](https://github.com/open-telemetry/opentelemetry-specification/blob/fc8289b8879f3a37e1eba5b4e445c94e74b20359/specification/logs/data-model.md) and sends them to OTLP logs collector. | ||
Pino transport for OpenTelemetry. Outputs logs in the [OpenTelemetry Log Data Model](https://github.com/open-telemetry/opentelemetry-specification/blob/fc8289b8879f3a37e1eba5b4e445c94e74b20359/specification/logs/data-model.md) and sends them to an OTLP logs collector. | ||
@@ -26,2 +26,41 @@ ## Install | ||
### Minimalistic example | ||
Make sure you have access to an OTEL collector. | ||
To start quickly, create a minimal configuration for OTEL collector in the `otel-collector-config.yaml` file: | ||
``` | ||
receivers: | ||
otlp: | ||
protocols: | ||
grpc: | ||
exporters: | ||
file: | ||
path: ./etc/test-logs/otlp-logs.log | ||
flush_interval: 1 | ||
logging: | ||
verbosity: basic | ||
processors: | ||
batch: | ||
service: | ||
pipelines: | ||
logs: | ||
receivers: [otlp] | ||
processors: [] | ||
exporters: [logging, file] | ||
``` | ||
The collector can then be ran with: | ||
``` | ||
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 | ||
``` | ||
Create an index.js file containing | ||
```js | ||
@@ -43,10 +82,17 @@ const pino = require('pino') | ||
(Also works in CommonJS) | ||
Install Pino and pino-opentelemetry-transport | ||
## Test locally | ||
``` | ||
npm install pino pino-opentelemetry-transport | ||
``` | ||
Create the log file to be mounted by OTLP collector container | ||
```touch otlp-logs.log``` | ||
Run the service setting the `OTEL_EXPORTER_OTLP_LOGS_ENDPOINT` and `OTEL_RESOURCE_ATTRIBUTES` env vars | ||
``` | ||
OTEL_EXPORTER_OTLP_LOGS_ENDPOINT=http://localhost:4317 OTEL_RESOURCE_ATTRIBUTES="service.name=my-service,service.version=1.2.3" node index.js | ||
``` | ||
## Test the repo locally | ||
Run the OTLP collector in a container | ||
@@ -64,3 +110,3 @@ | ||
Note that not all log entries will immediately be written to the `otlp-logs.log` file. The collector will flush to the disk eventualy. The flush will be forced if the collector receives a kill signal. | ||
Note that not all log entries will immediately be written to the `otlp-logs.log` file. The collector will flush to the disk eventually. The flush will be forced if the collector receives a kill signal. | ||
@@ -72,4 +118,6 @@ ## Options | ||
* `messageKey`: The key of the log message to be used as the OpenTelemetry log entry Body. Optional, value `msg` used by default (like in Pino itself). | ||
* `resourceAttributes`: Object containing [resource attributes](https://opentelemetry.io/docs/instrumentation/js/resources/). | ||
## License | ||
MIT |
@@ -72,5 +72,5 @@ 'use strict' | ||
match(records[0].hrTime, timeInputToHrTime(testStart)) | ||
match(records[0]._severityNumber, 1) | ||
match(records[0]._severityText, 'TRACE') | ||
match(records[0]._body, 'test message') | ||
match(records[0].severityNumber, 1) | ||
match(records[0].severityText, 'TRACE') | ||
match(records[0].body, 'test message') | ||
match(records[0].resource, { | ||
@@ -90,15 +90,15 @@ _attributes: { | ||
match(records[1]._severityNumber, 5) | ||
match(records[1]._severityText, 'DEBUG') | ||
match(records[2]._severityNumber, 9) | ||
match(records[2]._severityText, 'INFO') | ||
match(records[3]._severityNumber, 13) | ||
match(records[3]._severityText, 'WARN') | ||
match(records[4]._severityNumber, 17) | ||
match(records[4]._severityText, 'ERROR') | ||
match(records[5]._severityNumber, 21) | ||
match(records[5]._severityText, 'FATAL') | ||
match(records[1].severityNumber, 5) | ||
match(records[1].severityText, 'DEBUG') | ||
match(records[2].severityNumber, 9) | ||
match(records[2].severityText, 'INFO') | ||
match(records[3].severityNumber, 13) | ||
match(records[3].severityText, 'WARN') | ||
match(records[4].severityNumber, 17) | ||
match(records[4].severityText, 'ERROR') | ||
match(records[5].severityNumber, 21) | ||
match(records[5].severityText, 'FATAL') | ||
// In case of unexpected severity number, the severity number is set to the highest value. | ||
match(records[6]._severityNumber, 0) | ||
match(records[6]._severityText, 'UNSPECIFIED') | ||
match(records[6].severityNumber, 0) | ||
match(records[6].severityText, 'UNSPECIFIED') | ||
@@ -105,0 +105,0 @@ logger.shutdown() |
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
22123
8
119