Skip to content

Commit c753e8c

Browse files
authored
Merge pull request #8 from Arditc/main
Feat - Allowing the possibility to disable Invocation Log
2 parents 325a185 + 91793c9 commit c753e8c

File tree

2 files changed

+54
-22
lines changed

2 files changed

+54
-22
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ export default new TailExporter({
162162
headers: {
163163

164164
},
165+
defaultLogsEnabled: {
166+
invocationLog: true;
167+
};
165168
}),
166169
],
167170
maxBufferSize: 20,
@@ -170,6 +173,25 @@ export default new TailExporter({
170173
});
171174
```
172175

176+
### Default log
177+
178+
The Tail Exporter can emit a small set of built-in logs per sink via the `defaultLogsEnabled` option (used by sinks such as `OtelLogSink`). The most common default log is:
179+
180+
- `invocationLog` (default: `true`): emits a per-invocation log record containing metadata about the invocation (script name, execution model, outcome, versionId), timing information, and any global tags. This complements automatic `console` capture and is useful for tracing, auditing, and correlating metrics with individual invocations.
181+
182+
To disable the invocation log for a sink, set:
183+
184+
```ts
185+
new OtelLogSink({
186+
...
187+
defaultLogsEnabled: {
188+
invocationLog: false;
189+
};
190+
}),
191+
```
192+
193+
You can enable or disable default logs per sink when constructing the sink (see the `OtelLogSink` example above).
194+
173195
2. Set up Datadog API key:
174196

175197
```bash
@@ -240,3 +262,5 @@ export default new TailExporter({
240262
}
241263
});
242264
```
265+
266+

src/sinks/logs/otel.ts

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ export interface OtelLogSinkOptions {
1919
headers: Record<string, string>;
2020
scopeName?: string;
2121
scopeVersion?: string;
22+
defaultLogsEnabled: {
23+
invocationLog: boolean;
24+
};
2225
}
2326

2427
const ulid = ulidFactory();
@@ -34,6 +37,9 @@ export class OtelLogSink implements LogSink {
3437
scopeName: "workers-observability-utils",
3538
scopeVersion: "0.3.0",
3639
...options,
40+
defaultLogsEnabled: {
41+
invocationLog: options.defaultLogsEnabled?.invocationLog !== false,
42+
}
3743
};
3844
}
3945

@@ -78,28 +84,30 @@ export class OtelLogSink implements LogSink {
7884

7985
const logRecords: LogRecord[] = [];
8086

81-
// Add invocation log
82-
const invocationLog: LogRecord = {
83-
timeUnixNano: this.timestampToNanos(event.eventTimestamp || Date.now()),
84-
severityNumber: SeverityNumber.SEVERITY_NUMBER_INFO,
85-
severityText: "INFO",
86-
body: {
87-
stringValue: this.eventToMessage(event),
88-
},
89-
attributes: this.convertTagsToAttributes({
90-
...flatten({ event: event.event }),
91-
cpuTimeMs: event.cpuTime || 0,
92-
wallTimeMs: event.wallTime || 0,
93-
scriptVersion: event.scriptVersion?.id || "unknown",
94-
scriptName: event.scriptName || "unknown",
95-
executionModel: event.executionModel || "unknown",
96-
outcome: event.outcome,
97-
entrypoint: event.entrypoint || "default",
98-
request_id: requestId,
99-
log_type: "invocation",
100-
}),
101-
};
102-
logRecords.push(invocationLog);
87+
if (this.options.defaultLogsEnabled.invocationLog) {
88+
// Add invocation log
89+
const invocationLog: LogRecord = {
90+
timeUnixNano: this.timestampToNanos(event.eventTimestamp || Date.now()),
91+
severityNumber: SeverityNumber.SEVERITY_NUMBER_INFO,
92+
severityText: "INFO",
93+
body: {
94+
stringValue: this.eventToMessage(event),
95+
},
96+
attributes: this.convertTagsToAttributes({
97+
...flatten({ event: event.event }),
98+
cpuTimeMs: event.cpuTime || 0,
99+
wallTimeMs: event.wallTime || 0,
100+
scriptVersion: event.scriptVersion?.id || "unknown",
101+
scriptName: event.scriptName || "unknown",
102+
executionModel: event.executionModel || "unknown",
103+
outcome: event.outcome,
104+
entrypoint: event.entrypoint || "default",
105+
request_id: requestId,
106+
log_type: "invocation",
107+
}),
108+
};
109+
logRecords.push(invocationLog);
110+
}
103111

104112
// Add individual logs
105113
if (event.logs) {

0 commit comments

Comments
 (0)