Skip to content

Commit

Permalink
L-699 [edge] Allow to suppress warning about missing execution context (
Browse files Browse the repository at this point in the history
  • Loading branch information
PetrHeinz authored Nov 10, 2023
1 parent d739d20 commit 5b012b1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
17 changes: 14 additions & 3 deletions packages/edge/src/edge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
Context,
ILogLevel,
ILogtailLog,
ILogtailOptions,
ILogtailEdgeOptions,
LogLevel,
} from "@logtail/types";
import { Base } from "@logtail/core";
Expand All @@ -20,9 +20,17 @@ type Message = string | Error;
export class Edge extends Base {
private _warnedAboutMissingCtx: Boolean = false;

public constructor(sourceToken: string, options?: Partial<ILogtailOptions>) {
private readonly warnAboutMissingExecutionContext: Boolean;

public constructor(
sourceToken: string,
options?: Partial<ILogtailEdgeOptions>,
) {
super(sourceToken, options);

this.warnAboutMissingExecutionContext =
options?.warnAboutMissingExecutionContext ?? true;

// Sync function
const sync = async (logs: ILogtailLog[]): Promise<ILogtailLog[]> => {
const res = await fetch(this._options.endpoint, {
Expand Down Expand Up @@ -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 =
Expand Down
6 changes: 6 additions & 0 deletions packages/types/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 5b012b1

Please sign in to comment.