Skip to content

Commit

Permalink
chore: update documentation for logger with instrumentation
Browse files Browse the repository at this point in the history
fixes #60
  • Loading branch information
pragmaticivan committed Dec 11, 2021
1 parent b08de4e commit 67228b7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
18 changes: 16 additions & 2 deletions README.md
Expand Up @@ -16,7 +16,7 @@ For questions and support please use the official [Discord channel](https://disc

## Why

Setting up observability metrics with nestjs requires multiple libraries and patterns. OpenTelemetry has support for multiple exporters and types of metrics such as Prometheus Metrics.
Setting up observability metrics with nestjs requires multiple libraries and patterns. OpenTelemetry has support for multiple exporters and types of metrics such as Prometheus Metrics.

## Observability

Expand Down Expand Up @@ -288,7 +288,21 @@ When `metricExporter` is defined in otel SDK with a `PrometheusExporter`it will

## Using with a logger

### Pino
### Pino with instrumentation

This approach uses otel instrumentation to automatically inject spanId and traceId.

```ts
import { PinoInstrumentation } from '@opentelemetry/instrumentation-pino';

const otelSDK = new NodeSDK({
instrumentations: [new PinoInstrumentation()],
});
```

### Pino with custom formatter

This approach uses the global trace context for injecting SpanId and traceId as a property of your structured log.

```ts
import Pino, { Logger } from 'pino';
Expand Down
7 changes: 5 additions & 2 deletions src/tracing/trace.service.ts
Expand Up @@ -3,12 +3,15 @@ import { Injectable } from '@nestjs/common';

@Injectable()
export class TraceService {
public getTracer() {
return trace.getTracer('default');
}

public getSpan(): Span {
return trace.getSpan(context.active());
}

public startSpan(name: string): Span {
const tracer = trace.getTracer('default');
return tracer.startSpan(name);
return this.getTracer().startSpan(name);
}
}

0 comments on commit 67228b7

Please sign in to comment.