Skip to content

Commit 5b012b1

Browse files
authored
L-699 [edge] Allow to suppress warning about missing execution context (#94)
1 parent d739d20 commit 5b012b1

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

packages/edge/src/edge.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
Context,
55
ILogLevel,
66
ILogtailLog,
7-
ILogtailOptions,
7+
ILogtailEdgeOptions,
88
LogLevel,
99
} from "@logtail/types";
1010
import { Base } from "@logtail/core";
@@ -20,9 +20,17 @@ type Message = string | Error;
2020
export class Edge extends Base {
2121
private _warnedAboutMissingCtx: Boolean = false;
2222

23-
public constructor(sourceToken: string, options?: Partial<ILogtailOptions>) {
23+
private readonly warnAboutMissingExecutionContext: Boolean;
24+
25+
public constructor(
26+
sourceToken: string,
27+
options?: Partial<ILogtailEdgeOptions>,
28+
) {
2429
super(sourceToken, options);
2530

31+
this.warnAboutMissingExecutionContext =
32+
options?.warnAboutMissingExecutionContext ?? true;
33+
2634
// Sync function
2735
const sync = async (logs: ILogtailLog[]): Promise<ILogtailLog[]> => {
2836
const res = await fetch(this._options.endpoint, {
@@ -80,7 +88,10 @@ export class Edge extends Base {
8088

8189
if (ctx) {
8290
ctx.waitUntil(log);
83-
} else if (!this._warnedAboutMissingCtx) {
91+
} else if (
92+
this.warnAboutMissingExecutionContext &&
93+
!this._warnedAboutMissingCtx
94+
) {
8495
this._warnedAboutMissingCtx = true;
8596

8697
const warningMessage =

packages/types/src/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ export interface ILogtailOptions {
8080
**/
8181
sendLogsToBetterStack: boolean;
8282
}
83+
export interface ILogtailEdgeOptions extends ILogtailOptions {
84+
/**
85+
* Boolean to produce a warning when ExecutionContext hasn't been passed to the `log` method
86+
**/
87+
warnAboutMissingExecutionContext: boolean;
88+
}
8389

8490
export type ILogLevel = LogLevel | string;
8591
export enum LogLevel {

0 commit comments

Comments
 (0)