Skip to content

Commit 542d16b

Browse files
committed
feat: add method field to remaining server and stream-recognizer logs
Standardize structured logs for New Relic faceting across orchestrator, Shazam, bootstrap, Redis ping, shutdown, and a commented scheduler stub.
1 parent b14e9f6 commit 542d16b

6 files changed

Lines changed: 86 additions & 16 deletions

File tree

‎server/src/scheduler.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ class Scheduler {
138138
});
139139
140140
this.logger.info({
141+
method: 'Scheduler.slicePlaylists',
141142
message: '[AUTO REFRESH] SHORTEN ALL PLAYLISTS, every 4 hours',
142143
});
143144
}, 4 * 60 * 60 * 1000);

‎server/src/utils/terminate.js‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ const terminate = function(server, options = { coredump: false, timeout: 500 },
4747
// https://nodejs.org/api/net.html#net_server_close_callback
4848
server.close(error => {
4949
if (error) {
50-
logger.error(error);
50+
logger.error({
51+
method: 'terminate',
52+
message: 'HTTP server close failed',
53+
error,
54+
});
5155
return exit(1);
5256
}
5357

‎stream-recognizer/src/index.js‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const server = listenHost
3636
function onListen() {
3737
logger.info(
3838
{
39+
method: 'bootstrap.onListen',
3940
metadata: listenHost
4041
? { port, host: listenHost, component: 'bootstrap' }
4142
: { port, component: 'bootstrap' },
@@ -49,13 +50,19 @@ function onListen() {
4950
if (anyStationEnabled) {
5051
if (!probeBinary(ffmpegBin)) {
5152
logger.warn(
52-
{ metadata: { bin: ffmpegBin, component: 'bootstrap' } },
53+
{
54+
method: 'bootstrap.checkBinary',
55+
metadata: { bin: ffmpegBin, component: 'bootstrap' },
56+
},
5357
`ffmpeg not found. ${missingBinaryHint('ffmpeg', 'FFMPEG_BIN')}`,
5458
);
5559
}
5660
if (!probeBinary(fpcalcBin)) {
5761
logger.warn(
58-
{ metadata: { bin: fpcalcBin, component: 'bootstrap' } },
62+
{
63+
method: 'bootstrap.checkBinary',
64+
metadata: { bin: fpcalcBin, component: 'bootstrap' },
65+
},
5966
`fpcalc not found. ${missingBinaryHint('fpcalc', 'FPCALC_BIN')}`,
6067
);
6168
}
@@ -80,6 +87,7 @@ for (const station of stations) {
8087
}).catch((e) => {
8188
logger.error(
8289
{
90+
method: 'bootstrap.initialStationTick',
8391
err: e,
8492
metadata: { stationID: station.id, component: 'bootstrap' },
8593
},
@@ -92,6 +100,7 @@ for (const station of stations) {
92100
}).catch((e) => {
93101
logger.error(
94102
{
103+
method: 'bootstrap.scheduledStationTick',
95104
err: e,
96105
metadata: { stationID: station.id, component: 'bootstrap' },
97106
},
@@ -104,7 +113,10 @@ for (const station of stations) {
104113
}
105114

106115
function shutdown() {
107-
logger.info({ metadata: { component: 'bootstrap' } }, 'Shutting down');
116+
logger.info(
117+
{ method: 'bootstrap.shutdown', metadata: { component: 'bootstrap' } },
118+
'Shutting down',
119+
);
108120
for (const t of timers) {
109121
clearInterval(t);
110122
}

‎stream-recognizer/src/lib/redis_store.js‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,11 @@ export async function pingRedis(logger) {
168168
return { ok: true };
169169
} catch (e) {
170170
logger.error(
171-
{ err: e, metadata: { component: 'redis', operation: 'ping' } },
171+
{
172+
method: 'pingRedis',
173+
err: e,
174+
metadata: { component: 'redis', operation: 'ping' },
175+
},
172176
'Redis ping failed',
173177
);
174178
return { ok: false, reason: String(e?.message || e) };

‎stream-recognizer/src/pipeline/orchestrator.js‎

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ async function copyDebugWavIfEnabled(
183183
} catch (e) {
184184
log.warn(
185185
{
186+
method: 'copyDebugWavIfEnabled',
186187
err: e,
187188
metadata: { companionTxtPath, stationID: stationId },
188189
},
@@ -196,7 +197,11 @@ async function copyDebugWavIfEnabled(
196197
: { wavPath: debugCopyPath };
197198
} catch (e) {
198199
log.warn(
199-
{ err: e, metadata: { stationID: stationId, debugDir } },
200+
{
201+
method: 'copyDebugWavIfEnabled',
202+
err: e,
203+
metadata: { stationID: stationId, debugDir },
204+
},
200205
'Debug capture WAV copy failed',
201206
);
202207
return undefined;
@@ -309,6 +314,7 @@ export async function runStationTick(station, store, logger, options = {}) {
309314
if (cAttempt > 0) {
310315
log.info(
311316
{
317+
method: 'runStationTick',
312318
metadata: {
313319
stationID: station.id,
314320
captureAttempt: cAttempt + 1,
@@ -335,6 +341,7 @@ export async function runStationTick(station, store, logger, options = {}) {
335341
]);
336342
log.error(
337343
{
344+
method: 'runStationTick',
338345
err: e,
339346
metadata: {
340347
stationID: station.id,
@@ -350,6 +357,7 @@ export async function runStationTick(station, store, logger, options = {}) {
350357
}
351358
log.warn(
352359
{
360+
method: 'runStationTick',
353361
err: e,
354362
metadata: {
355363
stationID: station.id,
@@ -386,7 +394,10 @@ export async function runStationTick(station, store, logger, options = {}) {
386394

387395
if (gates.silence) {
388396
log.debug(
389-
{ metadata: { stationID: station.id, meanDb: gates.meanDb } },
397+
{
398+
method: 'runStationTick',
399+
metadata: { stationID: station.id, meanDb: gates.meanDb },
400+
},
390401
'skip: silence',
391402
);
392403
tickOutcome = 'skipped_silence';
@@ -401,6 +412,7 @@ export async function runStationTick(station, store, logger, options = {}) {
401412
if (gates.speechHeavy) {
402413
log.debug(
403414
{
415+
method: 'runStationTick',
404416
metadata: {
405417
stationID: station.id,
406418
speechFrameRatio: gates.speechFrameRatio,
@@ -426,7 +438,10 @@ export async function runStationTick(station, store, logger, options = {}) {
426438

427439
if (prevFp && fingerprint === prevFp) {
428440
log.debug(
429-
{ metadata: { stationID: station.id } },
441+
{
442+
method: 'runStationTick',
443+
metadata: { stationID: station.id },
444+
},
430445
'fingerprint unchanged; skip audio recognition APIs and Redis',
431446
);
432447
tickOutcome = 'skipped_fingerprint_unchanged';
@@ -457,6 +472,7 @@ export async function runStationTick(station, store, logger, options = {}) {
457472
const msg = `${name} was not used (SHAZAM_DISABLED=1).`;
458473
log.info(
459474
{
475+
method: 'runStationTick',
460476
metadata: {
461477
stationID: station.id,
462478
provider: id,
@@ -512,6 +528,7 @@ export async function runStationTick(station, store, logger, options = {}) {
512528
const debugCopyPath = debugCopy?.wavPath;
513529
log.info(
514530
{
531+
method: 'runStationTick',
515532
metadata: {
516533
stationID: station.id,
517534
capturePath: wavPath,
@@ -551,6 +568,7 @@ export async function runStationTick(station, store, logger, options = {}) {
551568
.join(' — ');
552569
log.info(
553570
{
571+
method: 'runStationTick',
554572
metadata: {
555573
stationID: station.id,
556574
provider: matchSource,
@@ -579,7 +597,10 @@ export async function runStationTick(station, store, logger, options = {}) {
579597

580598
if (prevKey === key) {
581599
log.debug(
582-
{ metadata: { stationID: station.id } },
600+
{
601+
method: 'runStationTick',
602+
metadata: { stationID: station.id },
603+
},
583604
'same track key as Redis; skip write',
584605
);
585606
tickOutcome = 'skipped_same_track_as_cache';
@@ -653,7 +674,11 @@ export async function runStationTick(station, store, logger, options = {}) {
653674
} catch (e) {
654675
tickOutcome = 'error';
655676
log.error(
656-
{ err: e, metadata: { stationID: station.id } },
677+
{
678+
method: 'runStationTick',
679+
err: e,
680+
metadata: { stationID: station.id },
681+
},
657682
'Station tick failed',
658683
);
659684
try {

‎stream-recognizer/src/providers/shazam.js‎

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -257,13 +257,19 @@ function logNoMatch(logger, body, reason) {
257257
? JSON.stringify(body).slice(0, 4000)
258258
: String(body);
259259
logger.info(
260-
{ metadata: { reason, responsePreview: preview } },
260+
{
261+
method: 'logNoMatch',
262+
metadata: { reason, responsePreview: preview },
263+
},
261264
'shazam: no usable track (set SHAZAM_DEBUG_RESPONSE=1 for full body on miss)',
262265
);
263266
if (process.env.SHAZAM_DEBUG_RESPONSE === '1') {
264267
try {
265268
logger.info(
266-
{ metadata: { full: JSON.stringify(body).slice(0, 12_000) } },
269+
{
270+
method: 'logNoMatch',
271+
metadata: { full: JSON.stringify(body).slice(0, 12_000) },
272+
},
267273
'shazam: raw response (truncated)',
268274
);
269275
} catch {
@@ -401,6 +407,7 @@ async function postDiscovery(
401407
const retryAfter = envInt('SHAZAM_429_RETRY_MS', 2500);
402408
logger.warn(
403409
{
410+
method: 'postDiscovery',
404411
metadata: {
405412
...(stationId != null ? { stationID: String(stationId) } : {}),
406413
status: res.status,
@@ -436,6 +443,7 @@ async function postDiscovery(
436443
if (canRetry) {
437444
logger.warn(
438445
{
446+
method: 'postDiscovery',
439447
metadata: {
440448
...(stationId != null ? { stationID: String(stationId) } : {}),
441449
segmentIndex,
@@ -458,6 +466,7 @@ async function postDiscovery(
458466
if (attempt > 0) {
459467
logger.info(
460468
{
469+
method: 'postDiscovery',
461470
metadata: {
462471
...(stationId != null ? { stationID: String(stationId) } : {}),
463472
segmentIndex,
@@ -481,6 +490,7 @@ async function postDiscovery(
481490
}
482491
logger.warn(
483492
{
493+
method: 'postDiscovery',
484494
err: e,
485495
metadata: {
486496
...(stationId != null ? { stationID: String(stationId) } : {}),
@@ -577,7 +587,10 @@ export async function shazamIdentifyFromFile(wavPath, logger, options = {}) {
577587
};
578588

579589
if (!isShazamEnabled()) {
580-
log.debug('shazam: skipped (SHAZAM_DISABLED=1)');
590+
log.debug(
591+
{ method: 'shazamIdentifyFromFile' },
592+
'shazam: skipped (SHAZAM_DISABLED=1)',
593+
);
581594
report([
582595
{ key: 'success', value: 1 },
583596
{ key: 'matched', value: 0 },
@@ -596,7 +609,11 @@ export async function shazamIdentifyFromFile(wavPath, logger, options = {}) {
596609
buffer = await readFile(wavPath);
597610
} catch (e) {
598611
log.error(
599-
{ err: e, metadata: { wavPath } },
612+
{
613+
method: 'shazamIdentifyFromFile',
614+
err: e,
615+
metadata: { wavPath },
616+
},
600617
'shazam: failed to read audio file',
601618
);
602619
report([
@@ -617,7 +634,10 @@ export async function shazamIdentifyFromFile(wavPath, logger, options = {}) {
617634
try {
618635
signatures = recognizeBytes(bytes);
619636
} catch (e) {
620-
log.error({ err: e }, 'shazam: recognizeBytes failed');
637+
log.error(
638+
{ method: 'shazamIdentifyFromFile', err: e },
639+
'shazam: recognizeBytes failed',
640+
);
621641
report([
622642
{ key: 'success', value: 0 },
623643
{ key: 'matched', value: 0 },
@@ -631,7 +651,10 @@ export async function shazamIdentifyFromFile(wavPath, logger, options = {}) {
631651
}
632652

633653
if (!Array.isArray(signatures) || signatures.length === 0) {
634-
log.info({}, 'shazam: no signatures from recognizeBytes');
654+
log.info(
655+
{ method: 'shazamIdentifyFromFile' },
656+
'shazam: no signatures from recognizeBytes',
657+
);
635658
report([
636659
{ key: 'success', value: 1 },
637660
{ key: 'matched', value: 0 },
@@ -696,6 +719,7 @@ export async function shazamIdentifyFromFile(wavPath, logger, options = {}) {
696719
: undefined;
697720
log.error(
698721
{
722+
method: 'shazamIdentifyFromFile',
699723
err: e,
700724
metadata: {
701725
segmentIndex: i,

0 commit comments

Comments
 (0)