Skip to content

Commit

Permalink
Context building slog sender (#10300)
Browse files Browse the repository at this point in the history
closes: #10269

## Description
Adds a slog sender which will build various contexts along the way and report them along with the slogs for better logs querying and identification

### Security Considerations
None

### Scaling Considerations
This uses a json file storage

### Documentation Considerations
This is a new slogger which can be opted into

### Testing Considerations
This will be deployed on testnets (already deployed on one of the testnets and log link is added in a comment below)

### Upgrade Considerations
This can be configured on existing deployments by bumping the telemetry package
  • Loading branch information
usmanmani1122 authored Oct 29, 2024
1 parent 7ae1f27 commit acbd3ae
Show file tree
Hide file tree
Showing 5 changed files with 607 additions and 6 deletions.
3 changes: 3 additions & 0 deletions packages/telemetry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@
"@endo/marshal": "^1.6.1",
"@endo/stream": "^1.2.7",
"@opentelemetry/api": "~1.3.0",
"@opentelemetry/api-logs": "0.53.0",
"@opentelemetry/exporter-prometheus": "~0.35.0",
"@opentelemetry/exporter-logs-otlp-http": "0.53.0",
"@opentelemetry/exporter-trace-otlp-http": "~0.35.0",
"@opentelemetry/resources": "~1.9.0",
"@opentelemetry/sdk-logs": "0.53.0",
"@opentelemetry/sdk-metrics": "~1.9.0",
"@opentelemetry/sdk-trace-base": "~1.9.0",
"@opentelemetry/semantic-conventions": "~1.27.0",
Expand Down
42 changes: 42 additions & 0 deletions packages/telemetry/src/context-aware-slog-file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* eslint-env node */

import { makeFsStreamWriter } from '@agoric/internal/src/node/fs-stream.js';
import { makeContextualSlogProcessor } from './context-aware-slog.js';
import { serializeSlogObj } from './serialize-slog-obj.js';

/**
* @param {import('./index.js').MakeSlogSenderOptions} options
*/
export const makeSlogSender = async options => {
const { CHAIN_ID, CONTEXTUAL_SLOGFILE } = options.env || {};
if (!CONTEXTUAL_SLOGFILE)
return console.warn(
'Ignoring invocation of slogger "context-aware-slog-file" without the presence of "CONTEXTUAL_SLOGFILE"',
);

const stream = await makeFsStreamWriter(CONTEXTUAL_SLOGFILE);

if (!stream)
return console.error(
`Couldn't create a write stream on file "${CONTEXTUAL_SLOGFILE}"`,
);

const contextualSlogProcessor = makeContextualSlogProcessor({
'chain-id': CHAIN_ID,
});

/**
* @param {import('./context-aware-slog.js').Slog} slog
*/
const slogSender = slog => {
const contextualizedSlog = contextualSlogProcessor(slog);

// eslint-disable-next-line prefer-template
stream.write(serializeSlogObj(contextualizedSlog) + '\n').catch(() => {});
};

return Object.assign(slogSender, {
forceFlush: () => stream.flush(),
shutdown: () => stream.close(),
});
};
Loading

0 comments on commit acbd3ae

Please sign in to comment.