Skip to content

Commit

Permalink
Merge pull request #54 from 10xLaCroixDrinker/refactor/multi-log-proc…
Browse files Browse the repository at this point in the history
…essor

refactor: dont reimplement MultiLogRecordProcessor
  • Loading branch information
Vunovati committed Mar 7, 2024
2 parents ec0bd43 + 022ed59 commit d3cb275
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 136 deletions.
15 changes: 1 addition & 14 deletions lib/create-log-processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,6 @@ const {
ConsoleLogRecordExporter
} = require('@opentelemetry/sdk-logs')

const { MultiLogRecordProcessor } = require('./multi-log-processor')

/**
* @param {LogRecordProcessorOptions | LogRecordProcessorOptions[]} [logRecordProcessorOptions]
*/
function createLogProcessor (logRecordProcessorOptions) {
return Array.isArray(logRecordProcessorOptions)
? new MultiLogRecordProcessor(
logRecordProcessorOptions.map(createLogRecordProcessor)
)
: createLogRecordProcessor(logRecordProcessorOptions)
}

/**
* @typedef {"batch" | "simple"} RecordProcessorType
* @typedef {Object} LogRecordProcessorOptions
Expand All @@ -29,7 +16,7 @@ function createLogProcessor (logRecordProcessorOptions) {
* @param {LogRecordProcessorOptions} [opts]
* @returns {import('@opentelemetry/sdk-logs').LogRecordProcessor}
*/
function createLogRecordProcessor (opts) {
function createLogProcessor (opts) {
const exporter = createExporter(opts?.exporterOptions)

if (opts?.recordProcessorType === 'simple') {
Expand Down
38 changes: 0 additions & 38 deletions lib/multi-log-processor.js

This file was deleted.

10 changes: 7 additions & 3 deletions lib/otlp-logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@ function getOtlpLogger (opts) {
)
})

loggerProvider.addLogRecordProcessor(
createLogProcessor(opts.logRecordProcessorOptions)
)
const logRecordProcessorOptionsArray = Array.isArray(opts.logRecordProcessorOptions) ? opts.logRecordProcessorOptions : [opts.logRecordProcessorOptions]

logRecordProcessorOptionsArray.forEach(logRecordProcessorOptions => {
loggerProvider.addLogRecordProcessor(
createLogProcessor(logRecordProcessorOptions)
)
})

logs.setGlobalLoggerProvider(loggerProvider)

Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"license": "MIT",
"dependencies": {
"@opentelemetry/api-logs": "^0.48.0",
"@opentelemetry/core": "^1.17.0",
"@opentelemetry/exporter-logs-otlp-grpc": "^0.48.0",
"@opentelemetry/exporter-logs-otlp-http": "^0.48.0",
"@opentelemetry/exporter-logs-otlp-proto": "^0.48.0",
Expand Down
42 changes: 11 additions & 31 deletions test/lib/create-log-processor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const {
const {
OTLPLogExporter: HttpExporter
} = require('@opentelemetry/exporter-logs-otlp-http')
const { MultiLogRecordProcessor } = require('../../lib/multi-log-processor')

test('createLogProcessor - no params', async ({ type }) => {
const logProcessor = createLogProcessor()
Expand Down Expand Up @@ -118,38 +117,19 @@ test('createLogProcessor - simple with http exporter', async ({ type }) => {
type(logProcessor._exporter, HttpExporter)
})

test('createLogProcessor - simple with single logRecordProcessorOption in array', async ({
test('createLogProcessor - batch with console exporter', async ({
type
}) => {
const logProcessor = createLogProcessor([
{
recordProcessorType: 'simple',
exporterOptions: {
protocol: 'console'
}
}
])

type(logProcessor, MultiLogRecordProcessor)
type(logProcessor.processors[0], SimpleLogRecordProcessor)
type(logProcessor.processors[0]._exporter, ConsoleLogRecordExporter)
})

test('createLogProcessor - batch with single logRecordProcessorOption', async ({
type
}) => {
const logProcessor = createLogProcessor([
{
recordProcessorType: 'batch',
exporterOptions: {
protocol: 'console'
},
processorConfig: {
maxQueueSize: 42
}
const logProcessor = createLogProcessor({
recordProcessorType: 'batch',
exporterOptions: {
protocol: 'console'
},
processorConfig: {
maxQueueSize: 42
}
])
})

type(logProcessor, MultiLogRecordProcessor)
type(logProcessor.processors[0], BatchLogRecordProcessor)
type(logProcessor, BatchLogRecordProcessor)
type(logProcessor._exporter, ConsoleLogRecordExporter)
})
49 changes: 0 additions & 49 deletions test/lib/multi-log-processor.test.js

This file was deleted.

0 comments on commit d3cb275

Please sign in to comment.