Skip to content

Commit

Permalink
Skip payload logging for container skills
Browse files Browse the repository at this point in the history
[changelog:changed]
  • Loading branch information
cdupuis committed Apr 26, 2021
1 parent 632d08e commit ae77043
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
3 changes: 2 additions & 1 deletion lib/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
} from "./handler/handler";
import { createHttpClient } from "./http";
import { debug } from "./log/console";
import { initLogging, runtime } from "./log/util";
import { initLogging, logPayload, runtime } from "./log/util";
import { mapSubscription } from "./map";
import {
PubSubCommandMessageClient,
Expand Down Expand Up @@ -243,6 +243,7 @@ export function createContext(
rt.skill.sha.slice(0, 7),
rt.node.version,
);
logPayload(context);
}
return context;
}
Expand Down
4 changes: 1 addition & 3 deletions lib/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
WebhookHandler,
} from "./handler/handler";
import { debug, error } from "./log";
import { logPayload } from "./log/util";
import { prepareStatus, StatusPublisher } from "./message";
import {
CommandIncoming,
Expand Down Expand Up @@ -74,7 +75,6 @@ export async function processEvent(
): Promise<void> {
const context = factory(event, ctx) as EventContext<any> &
ContextualLifecycle;
debug(`Incoming event message: ${JSON.stringify(event, replacer)}`);
if (isSubscriptionIncoming(event)) {
debug(
`Invoking event handler '${context.name}' for tx '${event.subscription.tx}'`,
Expand Down Expand Up @@ -104,7 +104,6 @@ export async function processCommand(
factory: ContextFactory = createContext,
): Promise<void> {
const context = factory(event, ctx) as CommandContext & ContextualLifecycle;
debug(`Incoming command message: ${JSON.stringify(event, replacer)}`);
debug(`Invoking command handler '${context.name}'`);
try {
const result = await invokeHandler(loader, context);
Expand Down Expand Up @@ -134,7 +133,6 @@ export async function processWebhook(
factory: ContextFactory = createContext,
): Promise<void> {
const context = factory(event, ctx) as WebhookContext & ContextualLifecycle;
debug(`Incoming webhook message: ${JSON.stringify(event, replacer)}`);
debug(`Invoking webhook handler '${context.name}'`);
try {
const result = await invokeHandler(loader, context);
Expand Down
33 changes: 31 additions & 2 deletions lib/log/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@
import { createLogger } from "@atomist/skill-logging";

import { Contextual } from "../handler/handler";
import { handleErrorSync } from "../util";
import { clearLogger, setLogger } from "./console";
import {
isCommandIncoming,
isEventIncoming,
isSubscriptionIncoming,
isWebhookIncoming,
} from "../payload";
import { handleErrorSync, replacer } from "../util";
import { clearLogger, debug, setLogger } from "./console";

export function initLogging(
context: {
Expand Down Expand Up @@ -99,3 +105,26 @@ export function runtime(): {
},
};
}

export function logPayload(ctx: Contextual<any, any>): void {
// Exit early for container skills
if (
(ctx.skill as any).artifacts?.some(
a => a.__typename === "AtomistSkillDockerArtifact",
)
) {
return;
}

const payload = ctx.trigger;
let label;
if (isEventIncoming(payload) || isSubscriptionIncoming(payload)) {
label = "event";
} else if (isCommandIncoming(payload)) {
label = "command";
} else if (isWebhookIncoming(payload)) {
label = "webhook";
}

debug(`Incoming ${label} message: ${JSON.stringify(payload, replacer)}`);
}

0 comments on commit ae77043

Please sign in to comment.