Skip to content

Commit f5a35da

Browse files
Add key to LoggerContext (#455)
1 parent 4436307 commit f5a35da

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

packages/restate-sdk/src/endpoint/handlers/generic.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
} from "../../logger.js";
3434
import * as vm from "./vm/sdk_shared_core_wasm_bindings.js";
3535
import { CompletablePromise } from "../../utils/completable_promise.js";
36+
import { HandlerKind } from "../../types/rpc.js";
3637

3738
export interface Headers {
3839
[name: string]: string | string[] | undefined;
@@ -278,9 +279,9 @@ export class GenericHandler implements RestateHandler {
278279
LogSource.USER,
279280
new LoggerContext(
280281
input.invocation_id,
281-
"",
282282
handler.component().name(),
283283
handler.name(),
284+
handler.kind() === HandlerKind.SERVICE ? undefined : input.key,
284285
additionalContext
285286
),
286287
() => !coreVm.is_processing()

packages/restate-sdk/src/logger.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,26 +115,27 @@ function readRestateLogLevel(): RestateLogLevel {
115115
}
116116

117117
export class LoggerContext {
118-
readonly fqMethodName: string;
118+
readonly invocationTarget: string;
119119

120120
constructor(
121121
readonly invocationId: string,
122-
packageName: string,
123-
serviceName: string,
124-
handlerName: string,
122+
readonly serviceName: string,
123+
readonly handlerName: string,
124+
readonly key?: string,
125125
readonly additionalContext?: { [name: string]: string }
126126
) {
127-
this.fqMethodName = packageName
128-
? `${packageName}.${serviceName}/${handlerName}`
129-
: `${serviceName}/${handlerName}`;
127+
this.invocationTarget =
128+
key === undefined || key.length === 0
129+
? `${serviceName}/${handlerName}`
130+
: `${serviceName}/${key}/${handlerName}`;
130131
}
131132
}
132133

133134
function formatLogPrefix(context?: LoggerContext): string {
134135
if (context === undefined) {
135136
return "[restate] ";
136137
}
137-
let prefix = `[restate] [${context.fqMethodName}][${context.invocationId}]`;
138+
let prefix = `[restate] [${context.invocationTarget}][${context.invocationId}]`;
138139
if (context.additionalContext !== undefined) {
139140
for (const [k, v] of Object.entries(context.additionalContext)) {
140141
prefix = prefix + `[${k}: ${v}]`;

0 commit comments

Comments
 (0)