Skip to content

Commit e1dc8d0

Browse files
committed
Support node auto instrumentation config
1 parent cad1409 commit e1dc8d0

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

.changeset/some-pumas-cheer.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"logfire": minor
3+
---
4+
5+
Allow configuration of node auto instrumentations

packages/logfire/src/logfireConfig.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { DiagLogLevel } from '@opentelemetry/api'
2+
import { InstrumentationConfigMap } from '@opentelemetry/auto-instrumentations-node'
23
import { MetricReader } from '@opentelemetry/sdk-metrics'
34
import { IdGenerator, SpanProcessor } from '@opentelemetry/sdk-trace-base'
45
import * as logfireApi from '@pydantic/logfire-api'
@@ -68,6 +69,10 @@ export interface LogfireConfigOptions {
6869
* Set to False to disable sending all metrics, or provide a MetricsOptions object to configure metrics, e.g. additional metric readers.
6970
*/
7071
metrics?: false | MetricsOptions
72+
/**
73+
* The node auto instrumentations to use. See [Node Auto Instrumentations](https://opentelemetry.io/docs/languages/js/libraries/#registration) for more information.
74+
*/
75+
nodeAutoInstrumentations?: InstrumentationConfigMap
7176
/**
7277
* The otel scope to use for the logfire API. Defaults to 'logfire'.
7378
*/
@@ -101,6 +106,13 @@ export interface LogfireConfigOptions {
101106
const DEFAULT_OTEL_SCOPE = 'logfire'
102107
const TRACE_ENDPOINT_PATH = 'v1/traces'
103108
const METRIC_ENDPOINT_PATH = 'v1/metrics'
109+
const DEFAULT_AUTO_INSTRUMENTATION_CONFIG: InstrumentationConfigMap = {
110+
// https://opentelemetry.io/docs/languages/js/libraries/#registration
111+
// This particular instrumentation creates a lot of noise on startup
112+
'@opentelemetry/instrumentation-fs': {
113+
enabled: false,
114+
},
115+
}
104116

105117
export interface LogfireConfig {
106118
additionalSpanProcessors: SpanProcessor[]
@@ -113,6 +125,7 @@ export interface LogfireConfig {
113125
idGenerator: IdGenerator
114126
metricExporterUrl: string
115127
metrics: false | MetricsOptions | undefined
128+
nodeAutoInstrumentations: InstrumentationConfigMap
116129
otelScope: string
117130
sendToLogfire: boolean
118131
serviceName: string | undefined
@@ -132,6 +145,7 @@ const DEFAULT_LOGFIRE_CONFIG: LogfireConfig = {
132145
idGenerator: new ULIDGenerator(),
133146
metricExporterUrl: '',
134147
metrics: undefined,
148+
nodeAutoInstrumentations: DEFAULT_AUTO_INSTRUMENTATION_CONFIG,
135149
otelScope: DEFAULT_OTEL_SCOPE,
136150
sendToLogfire: false,
137151
serviceName: process.env.LOGFIRE_SERVICE_NAME,
@@ -168,6 +182,7 @@ export function configure(config: LogfireConfigOptions = {}) {
168182
idGenerator: cnf.advanced?.idGenerator ?? new ULIDGenerator(),
169183
metricExporterUrl: `${baseUrl}/${METRIC_ENDPOINT_PATH}`,
170184
metrics: cnf.metrics,
185+
nodeAutoInstrumentations: cnf.nodeAutoInstrumentations ?? DEFAULT_AUTO_INSTRUMENTATION_CONFIG,
171186
sendToLogfire,
172187
serviceName: cnf.serviceName ?? env.LOGFIRE_SERVICE_NAME,
173188
serviceVersion: cnf.serviceVersion ?? env.LOGFIRE_SERVICE_VERSION,

packages/logfire/src/sdk.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,7 @@ export function start() {
4848
autoDetectResources: false,
4949
contextManager,
5050
idGenerator: new ULIDGenerator(),
51-
instrumentations: [
52-
getNodeAutoInstrumentations({
53-
// https://opentelemetry.io/docs/languages/js/libraries/#registration
54-
// This particular instrumentation creates a lot of noise on startup
55-
'@opentelemetry/instrumentation-fs': {
56-
enabled: false,
57-
},
58-
}),
59-
],
51+
instrumentations: [getNodeAutoInstrumentations(logfireConfig.nodeAutoInstrumentations)],
6052
metricReader: logfireConfig.metrics === false ? undefined : periodicMetricReader(),
6153
resource,
6254
spanProcessors: [processor, ...logfireConfig.additionalSpanProcessors],

0 commit comments

Comments
 (0)