diff --git a/packages/edge/src/edge.ts b/packages/edge/src/edge.ts index 4fe4731..c91b66f 100644 --- a/packages/edge/src/edge.ts +++ b/packages/edge/src/edge.ts @@ -4,7 +4,7 @@ import { Context, ILogLevel, ILogtailLog, - ILogtailOptions, + ILogtailEdgeOptions, LogLevel, } from "@logtail/types"; import { Base } from "@logtail/core"; @@ -20,9 +20,17 @@ type Message = string | Error; export class Edge extends Base { private _warnedAboutMissingCtx: Boolean = false; - public constructor(sourceToken: string, options?: Partial) { + private readonly warnAboutMissingExecutionContext: Boolean; + + public constructor( + sourceToken: string, + options?: Partial, + ) { super(sourceToken, options); + this.warnAboutMissingExecutionContext = + options?.warnAboutMissingExecutionContext ?? true; + // Sync function const sync = async (logs: ILogtailLog[]): Promise => { const res = await fetch(this._options.endpoint, { @@ -80,7 +88,10 @@ export class Edge extends Base { if (ctx) { ctx.waitUntil(log); - } else if (!this._warnedAboutMissingCtx) { + } else if ( + this.warnAboutMissingExecutionContext && + !this._warnedAboutMissingCtx + ) { this._warnedAboutMissingCtx = true; const warningMessage = diff --git a/packages/types/src/types.ts b/packages/types/src/types.ts index 2e27008..1e92a01 100644 --- a/packages/types/src/types.ts +++ b/packages/types/src/types.ts @@ -80,6 +80,12 @@ export interface ILogtailOptions { **/ sendLogsToBetterStack: boolean; } +export interface ILogtailEdgeOptions extends ILogtailOptions { + /** + * Boolean to produce a warning when ExecutionContext hasn't been passed to the `log` method + **/ + warnAboutMissingExecutionContext: boolean; +} export type ILogLevel = LogLevel | string; export enum LogLevel {