Skip to content

Commit

Permalink
feat: add log correlation/injection (#121)
Browse files Browse the repository at this point in the history
* feat: add log correlation

* chore: improve README

* chore: update CHANGELOG

* chore: add loggers to peer dependencies meta

* fix: always try to load logging instrumentations

* fix: read service name from resource

* feat: add optional service.version and service.environment to log inject

* fix: prefer resource information loaded by env detector

* fix: service name precedence
  • Loading branch information
seemk authored Jun 7, 2021
1 parent 63127ca commit 470288d
Show file tree
Hide file tree
Showing 12 changed files with 778 additions and 26 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

- Add support for injecting trace context into logs.
([#121](https://github.com/signalfx/splunk-otel-js/pull/121))

## 0.8.0 (04-15-2021)

- Added support for `aws-sdk`, `mongoose`, `sequelize`, `typeorm` and `kafkajs`.
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ You can also instrument your app with code as described [here](#instrument-with-
| SPLUNK_ACCESS_TOKEN | acceessToken | | | The optional organization access token for trace submission requests. |
| SPLUNK_MAX_ATTR_LENGTH | maxAttrLength | 1200 | Maximum length of string attribute value in characters. Longer values are truncated. |
| SPLUNK_CONTEXT_SERVER_TIMING_ENABLED | serverTimingEnabled | true | Enable injection of `Server-Timing` header to HTTP responses. |
| SPLUNK_LOGS_INJECTION | logInjectionEnabled | false | Enable injecting of trace ID, span ID and service name to log records. Please note that the corresponding logging library instrumentation needs to be installed. |
| OTEL_RESOURCE_ATTRIBUTES | | unset | Comma-separated list of resource attributes added to every reported span. <details><summary>Example</summary>`key1=val1,key2=val2`</details>
| OTEL_TRACE_ENABLED | | `true` | Globally enables tracer creation and auto-instrumentation. |

Expand Down Expand Up @@ -158,6 +159,8 @@ startTracing({

- `serverTimingEnabled`: corresponds to the `SPLUNK_SERVER_TIMING_ENABLED` environment variable. Defaults to false. Enables injection of `Server-Timing` header to responses.

- `logInjectionEnabled`: corresponds to the `SPLUNK_LOGS_INJECTION` environment variable. Defaults to false. Injects trace ID, span ID and service name to the log records. Service version or deployment environment will be injected if available in the [configured resource](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/semantic_conventions/README.md). Supported logging libraries: bunyan, pino, winston.

- `tracerConfig`: a JS object that is merged into the default tracer config replacing any existing keys and is passed on to the tracer provider during initialization. This can be used to customize the tracer provider or tracer. Must satisfy [`TracerConfig` interface](https://github.com/open-telemetry/opentelemetry-js/blob/71ba83a0dc51118e08e3148c788b81fe711003e7/packages/opentelemetry-tracing/src/types.ts#L26)

- `spanExporterFactory`: A function that accepts the options passed to startTracing function and returns a new instance of SpanExporter. When set, this function will be used to create a new exporter and the returned exporter will be used in the pipeline.
Expand Down Expand Up @@ -221,6 +224,14 @@ opentelemetry-instrumentation-amqplib
opentelemetry-instrumentation-elasticsearch
```

If log injection is enabled, the corresponding logging library package will need to be installed beforehand. Supported logging library instrumentations:

```
@opentelemetry/instrumentation-bunyan
@opentelemetry/instrumentation-pino
@opentelemetry/instrumentation-winston
```

You can find more instrumentation packages over at the [OpenTelemetry Registry](https://opentelemetry.io/registry/?language=js) and enable them manually
as described above.

Expand Down
Loading

0 comments on commit 470288d

Please sign in to comment.