@grow-codes/grafana-loki 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +53 -0
- package/lib/{chunk-553Q2KB5.cjs → chunk-VGAJJR3M.cjs} +2 -2
- package/lib/{chunk-553Q2KB5.cjs.map → chunk-VGAJJR3M.cjs.map} +1 -1
- package/lib/{chunk-KTHP35QG.js → chunk-ZH5T5C4R.js} +2 -2
- package/lib/{chunk-KTHP35QG.js.map → chunk-ZH5T5C4R.js.map} +1 -1
- package/lib/index.cjs +391 -142
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +124 -6
- package/lib/index.d.ts +124 -6
- package/lib/index.js +257 -15
- package/lib/index.js.map +1 -1
- package/lib/{query-CofVHbt1.d.cts → query-BYQW0k9P.d.cts} +2 -2
- package/lib/{query-CofVHbt1.d.ts → query-BYQW0k9P.d.ts} +2 -2
- package/lib/testing/index.cjs +14 -14
- package/lib/testing/index.cjs.map +1 -1
- package/lib/testing/index.js +1 -1
- package/lib/testing/index.js.map +1 -1
- package/package.json +2 -1
package/lib/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { L as LokiError, A as Attributes, a as LogRecord, b as AttrValue, c as LogClient, S as Severity, d as LogExporter, E as ExportOptions,
|
|
2
|
-
export {
|
|
1
|
+
import { L as LokiError, A as Attributes, a as LogRecord, b as AttrValue, c as LogClient, S as Severity, R as RedactionOptions, d as Logger, e as LogExporter, E as ExportOptions, f as ExportResult, B as BaseLogQueryClient, g as LogSearchOptions, h as LogSearchResult, T as TailOptions, i as TailHandle, H as HealthStatus, j as BatchingLogClientOptions, k as BatchingLogClient } from './query-BYQW0k9P.cjs';
|
|
2
|
+
export { l as AuthenticationError, m as BatchOptions, n as BatchProcessor, o as BatchStats, C as CancelledError, p as ConfigError, q as ConflictError, D as DEFAULT_BATCH_OPTIONS, r as DEFAULT_REDACT_KEYS, s as DropPolicy, t as DropReason, u as ErrorCode, v as ErrorDetails, w as LogInput, x as LogQueryClient, y as LogSink, z as LoggerOptions, N as NotFoundError, P as PermissionDeniedError, F as RateLimitError, G as RedactionProcessor, I as ResolvedBatchOptions, J as TimeoutError, U as UnavailableError, K as UnsupportedError, M as UnsupportedLogQueryClient, V as ValidationError, W as WaitForLogOptions, O as canonicalSeverity, Q as codeForStatus, X as errorForCode, Y as errorForStatus, Z as healthStatus, _ as isHealthyWord, $ as isLokiError, a0 as parseSeverity, a1 as pollTail, a2 as probeHealth, a3 as reasonForCode, a4 as resolveBatchOptions, a5 as severityText, a6 as waitForLog } from './query-BYQW0k9P.cjs';
|
|
3
3
|
import { Dispatcher } from 'undici';
|
|
4
4
|
import { Writable } from 'node:stream';
|
|
5
5
|
|
|
@@ -449,6 +449,12 @@ declare class HttpTransport {
|
|
|
449
449
|
constructor(options: TransportOptions);
|
|
450
450
|
/** Whether {@link close} was called. */
|
|
451
451
|
get closed(): boolean;
|
|
452
|
+
/**
|
|
453
|
+
* Throws `CancelledError` (`"<operation>: client is closed"`, not retryable) once {@link close}
|
|
454
|
+
* was called (SPEC §2.4). Requests check this themselves; service methods that send no request
|
|
455
|
+
* (cached reads, local helpers) call it first.
|
|
456
|
+
*/
|
|
457
|
+
ensureOpen(operation: string): void;
|
|
452
458
|
/** Builds the absolute URL for a path and query. */
|
|
453
459
|
buildUrl(path: string, query?: Readonly<Record<string, QueryValue>>): URL;
|
|
454
460
|
/** Redacts known secrets from a text (error messages, vendor text). */
|
|
@@ -479,13 +485,13 @@ declare class HttpTransport {
|
|
|
479
485
|
declare function redactSecretsInText(text: string): string;
|
|
480
486
|
|
|
481
487
|
/** Package version (kept in sync by release-please). */
|
|
482
|
-
declare const SDK_VERSION = "0.
|
|
488
|
+
declare const SDK_VERSION = "0.2.0";
|
|
483
489
|
/** Catalog key of the service (`grafana-loki`). */
|
|
484
490
|
declare const PACKAGE_KEY = "grafana-loki";
|
|
485
491
|
/** Language tag used in the User-Agent. */
|
|
486
492
|
declare const LANGUAGE = "typescript";
|
|
487
493
|
/** sdk-kit version this package was generated from. */
|
|
488
|
-
declare const SDK_KIT_VERSION = "0.
|
|
494
|
+
declare const SDK_KIT_VERSION = "0.3.0";
|
|
489
495
|
|
|
490
496
|
declare const INSPECT: unique symbol;
|
|
491
497
|
/** Longest tenant id Loki accepts (bytes). */
|
|
@@ -685,6 +691,118 @@ declare class WinstonTransport extends Writable {
|
|
|
685
691
|
close(): void;
|
|
686
692
|
}
|
|
687
693
|
|
|
694
|
+
/** Top-level stdout field: `"sdk"` = the SDK also exports the record (collector skips the line),
|
|
695
|
+
* `"sdk_failed"` = the SDK export failed or dropped it (collector ships the line). */
|
|
696
|
+
declare const LOG_SHIPPED_FIELD = "log_shipped";
|
|
697
|
+
/** What {@link connectLogClient} returns: the SDK transport and how to release it. */
|
|
698
|
+
interface LogConnection {
|
|
699
|
+
/** Batching log client of this package. */
|
|
700
|
+
logs: LogClient;
|
|
701
|
+
/** Flushes and closes the client (and the service client behind it). */
|
|
702
|
+
close(): Promise<void>;
|
|
703
|
+
}
|
|
704
|
+
/** Builds a {@link LogConnection} (service connector or a test seam); `undefined` = stdout only. */
|
|
705
|
+
type LogConnector = (options: {
|
|
706
|
+
resource: Attributes;
|
|
707
|
+
env: Readonly<Record<string, string | undefined>>;
|
|
708
|
+
/** Pass as `batch.onDrop`: records the SDK could not export are re-emitted on stdout. */
|
|
709
|
+
onDropped: (records: LogRecord[]) => void;
|
|
710
|
+
}) => LogConnection | undefined;
|
|
711
|
+
/** Options of {@link initLogging}. */
|
|
712
|
+
interface InitLoggingOptions {
|
|
713
|
+
/** `service.name` (default `GROW_SERVICE_NAME` > `OTEL_SERVICE_NAME` > `"unknown_service"`). */
|
|
714
|
+
service?: string;
|
|
715
|
+
/** Minimum level: trace|debug|info|warn|error|fatal (default `LOG_LEVEL` > `info`). */
|
|
716
|
+
level?: string;
|
|
717
|
+
/** Write JSON lines to stdout (default true). */
|
|
718
|
+
stdout?: boolean;
|
|
719
|
+
/** Ship through this package (default: `GROW_LOGGING_PROVIDER` equals the package key). */
|
|
720
|
+
ship?: boolean;
|
|
721
|
+
/** Extra redaction keys/patterns (default keys always apply). */
|
|
722
|
+
redaction?: RedactionOptions;
|
|
723
|
+
/** Environment (default `process.env`). */
|
|
724
|
+
env?: Readonly<Record<string, string | undefined>>;
|
|
725
|
+
/** Line writer (default `process.stdout`). Test seam. */
|
|
726
|
+
write?: (line: string) => void;
|
|
727
|
+
/** Connector override (tests, custom clients). Default: this package's `connectLogClient`. */
|
|
728
|
+
connect?: LogConnector;
|
|
729
|
+
}
|
|
730
|
+
/** Handle returned by {@link initLogging}. */
|
|
731
|
+
interface LoggingHandle {
|
|
732
|
+
/** The root logger (stdout JSON + SDK transport). */
|
|
733
|
+
logger: Logger;
|
|
734
|
+
/** The SDK log client when records are shipped, else `undefined`. */
|
|
735
|
+
logs: LogClient | undefined;
|
|
736
|
+
/** `true` when records are shipped through the SDK (stdout lines carry `log_shipped:"sdk"`). */
|
|
737
|
+
shipped: boolean;
|
|
738
|
+
/** `service.name` of every record. */
|
|
739
|
+
service: string;
|
|
740
|
+
/** Exports everything queued now (no-op without SDK transport). */
|
|
741
|
+
flush(timeoutMs?: number): Promise<void>;
|
|
742
|
+
/** Flushes and closes the SDK transport; idempotent. A new {@link initLogging} starts over. */
|
|
743
|
+
close(): Promise<void>;
|
|
744
|
+
/** Sends `message` (e.g. `foundation-canary-<token>`) through the SDK only and flushes. */
|
|
745
|
+
canary(message: string, attributes?: Attributes): Promise<boolean>;
|
|
746
|
+
/** A writable stream for `pino(…, stream)`: stdout copy + SDK transport. */
|
|
747
|
+
pinoStream(): Writable;
|
|
748
|
+
}
|
|
749
|
+
/** Runs `fn` with `requestId` attached to every record logged inside it. */
|
|
750
|
+
declare function withRequestId<T>(requestId: string, fn: () => T): T;
|
|
751
|
+
/** The request id of the current request ({@link withRequestId} / `requestLogger()`). */
|
|
752
|
+
declare function currentRequestId(): string | undefined;
|
|
753
|
+
/** The handle of the last {@link initLogging} call, if any. */
|
|
754
|
+
declare function getLogging(): LoggingHandle | undefined;
|
|
755
|
+
/**
|
|
756
|
+
* Converts one record into the stdout JSON line (flat, collector friendly). `marker` is written
|
|
757
|
+
* as the top-level {@link LOG_SHIPPED_FIELD} (`"sdk"`, `"sdk_failed"`); `undefined` omits it.
|
|
758
|
+
*/
|
|
759
|
+
declare function stdoutLine(record: LogRecord, marker?: string): string;
|
|
760
|
+
/**
|
|
761
|
+
* Initialises logging once per process: JSON lines on stdout (always, unless `stdout: false`) and,
|
|
762
|
+
* when `GROW_LOGGING_PROVIDER` names this package, the SDK transport built by `connectLogClient`
|
|
763
|
+
* from the package's own `GROW_<KEY>_*` variables (stdout lines are then marked
|
|
764
|
+
* `log_shipped:"sdk"`). Never throws for an unreachable logging service. Call it after
|
|
765
|
+
* `loadConfig()` of the secrets package.
|
|
766
|
+
*
|
|
767
|
+
* ```ts
|
|
768
|
+
* const { logger, flush } = initLogging({ service: "orders" });
|
|
769
|
+
* logger.info("started", { port: 3000 });
|
|
770
|
+
* ```
|
|
771
|
+
*/
|
|
772
|
+
declare function initLogging(opts?: InitLoggingOptions): LoggingHandle;
|
|
773
|
+
|
|
774
|
+
/** Minimal request shape (Node `IncomingMessage`, Express, Nest on Express). */
|
|
775
|
+
interface RequestLike {
|
|
776
|
+
method?: string;
|
|
777
|
+
url?: string;
|
|
778
|
+
originalUrl?: string;
|
|
779
|
+
headers: Record<string, string | string[] | undefined>;
|
|
780
|
+
}
|
|
781
|
+
/** Minimal response shape (Node `ServerResponse`). */
|
|
782
|
+
interface ResponseLike {
|
|
783
|
+
statusCode: number;
|
|
784
|
+
setHeader(name: string, value: string): unknown;
|
|
785
|
+
once(event: "finish" | "close", listener: () => void): unknown;
|
|
786
|
+
}
|
|
787
|
+
/** Options of {@link requestLogger}. */
|
|
788
|
+
interface RequestLoggerOptions {
|
|
789
|
+
/** Logger to use (default: the `initLogging()` logger). */
|
|
790
|
+
logger?: Logger;
|
|
791
|
+
/** Header that carries the request id (default `x-request-id`). */
|
|
792
|
+
header?: string;
|
|
793
|
+
/** Paths that are not logged (default `/health/live`, `/health/ready`). Prefix match. */
|
|
794
|
+
skip?: readonly string[];
|
|
795
|
+
}
|
|
796
|
+
/** Connect/Express style middleware. */
|
|
797
|
+
type RequestMiddleware = (req: RequestLike, res: ResponseLike, next: (err?: unknown) => void) => void;
|
|
798
|
+
/**
|
|
799
|
+
* Request middleware for Express, NestJS (`app.use(requestLogger())`) and plain Node `http`:
|
|
800
|
+
* reuses or creates the request id (`x-request-id`, echoed on the response), attaches it to every
|
|
801
|
+
* record logged while the request runs, and logs one `request completed` record with method,
|
|
802
|
+
* path, status and duration.
|
|
803
|
+
*/
|
|
804
|
+
declare function requestLogger(opts?: RequestLoggerOptions): RequestMiddleware;
|
|
805
|
+
|
|
688
806
|
/** Label names allowed by Loki (Prometheus rules). */
|
|
689
807
|
declare const LABEL_NAME_PATTERN: RegExp;
|
|
690
808
|
/**
|
|
@@ -1338,5 +1456,5 @@ declare function snappyCompress(data: Uint8Array): Uint8Array;
|
|
|
1338
1456
|
*/
|
|
1339
1457
|
declare function decodeRpcStatusMessage(bytes: Uint8Array): string | undefined;
|
|
1340
1458
|
|
|
1341
|
-
export { ALL_STREAMS_SELECTOR, AttrValue, Attributes, BaseLogQueryClient, BatchingLogClient, BatchingLogClientOptions, CardinalityGuard, DEFAULT_ALLOWED_LABELS, DEFAULT_REQUEST_ID_HEADERS, DEFAULT_TIMEOUTS, ENCODING_FLAGS_HEADER, EnvReader, ExportOptions, ExportResult, HealthStatus, HttpTransport, LABEL_NAME_PATTERN, LANGUAGE, LogClient, LogExporter, LogQL, LogRecord, LogSearchOptions, LogSearchResult, LokiClient, LokiConfig, LokiError, LokiLogExporter, LokiLogQueryClient, LokiOtlpExporter, MAX_QUERY_LIMIT, MAX_TENANT_ID_LENGTH, MAX_VENDOR_TEXT, MIN_SECRET_LENGTH, OTLP_SCOPE_NAME, PACKAGE_KEY, REDACTED, RESERVED_METADATA_KEYS, RetryPolicy, SDK_KIT_VERSION, SDK_VERSION, SENSITIVE_FIELD_PARTS, Secret, Severity, TENANT_HEADER, TailHandle, TailOptions, VENDOR_ENV, WinstonTransport, attrToString, createDispatcher, createPinoTransport, dateToNanos, decodeBuildInfo, decodeCursor, decodeEntry, decodeIndexStats, decodeQueryResult, decodeRpcStatusMessage, decodeSeries, decodeStreams, decodeStringList, decodeTailFrame, definedOnly, describeCommonConfig, encodeCursor, encodePushRequest, entryToLogRecord, formatLabelSet, isIdempotentMethod, isRetryableStatus, isSensitiveField, isSensitiveHeader, isValidLabelName, logRecordByteSize, logRecordFromJson, logRecordToJson, mergeOptions, mergeStreams, msToDuration, nanosToDate, normalizeLabelName, optionalNanos, parseBool, parseDuration, parseInteger, parseLogRecord, parseRetryAfter, pinoLevelToSeverity, pinoLineToRecord, pollUntil, quoteLogQL, readCommonEnv, recordsToOtlpJson, recordsToStreams, redactError, redactFields, redactHeaders, redactSecretsInText, redactText, redactUrl, resolveCommonConfig, safeCall, safeLogger, secondsToDate, secretValues, serializeLogRecord, silentLogger, sleep, snappyCompress, stringMap, tenantIdProblem, throwIfAborted, toAttrValue, toAttributes, toNanos, toOtlpValue, toSearchLogQL, validateCommonConfig, validateLabelName, validateLabels, winstonLevelToSeverity };
|
|
1342
|
-
export type { CallOptions, CardinalityGuardOptions, ClientInternals, ClientLogger, CommonConfig, CommonConfigOptions, CommonVendorEnv, Direction, EnvHit, EnvMap, ErrorClassifier, ErrorInfo, ErrorResponse, HeadersInput, Hooks, IndexOptions, KnownSecret, LabelsOptions, LiveTailOptions, LogFields, LogRecordJson, LokiBuildInfo, LokiClientShared, LokiConfigOptions, LokiDroppedEntry, LokiEntry, LokiEntryResult, LokiIndexStats, LokiLogClientOptions, LokiLogExporterOptions, LokiMatrixSeries, LokiPusher, LokiQueryResult, LokiQuerySource, LokiResultType, LokiSample, LokiStream, LokiStreamResult, LokiTail, LokiTailFrame, LokiTime, LokiVectorSample, MatchOperator, MergedEntry, NumericOperator, OtlpAnyValue, OtlpKeyValue, OtlpPushOptions, PinoTransportOptions, PollOptions, PushFormat, PushOptions, QueryOptions, QueryRangeOptions, QueryValue, RequestInfo, RequestOptions, ResponseInfo, ResponseType, RetryPolicyOptions, SeriesOptions, TailCallbacks, TimeRangeOptions, TlsOptions, TransportOptions, TransportResponse, VolumeOptions, VolumeRangeOptions, WinstonInfo, WinstonTransportOptions };
|
|
1459
|
+
export { ALL_STREAMS_SELECTOR, AttrValue, Attributes, BaseLogQueryClient, BatchingLogClient, BatchingLogClientOptions, CardinalityGuard, DEFAULT_ALLOWED_LABELS, DEFAULT_REQUEST_ID_HEADERS, DEFAULT_TIMEOUTS, ENCODING_FLAGS_HEADER, EnvReader, ExportOptions, ExportResult, HealthStatus, HttpTransport, LABEL_NAME_PATTERN, LANGUAGE, LOG_SHIPPED_FIELD, LogClient, LogExporter, LogQL, LogRecord, LogSearchOptions, LogSearchResult, Logger, LokiClient, LokiConfig, LokiError, LokiLogExporter, LokiLogQueryClient, LokiOtlpExporter, MAX_QUERY_LIMIT, MAX_TENANT_ID_LENGTH, MAX_VENDOR_TEXT, MIN_SECRET_LENGTH, OTLP_SCOPE_NAME, PACKAGE_KEY, REDACTED, RESERVED_METADATA_KEYS, RedactionOptions, RetryPolicy, SDK_KIT_VERSION, SDK_VERSION, SENSITIVE_FIELD_PARTS, Secret, Severity, TENANT_HEADER, TailHandle, TailOptions, VENDOR_ENV, WinstonTransport, attrToString, createDispatcher, createPinoTransport, currentRequestId, dateToNanos, decodeBuildInfo, decodeCursor, decodeEntry, decodeIndexStats, decodeQueryResult, decodeRpcStatusMessage, decodeSeries, decodeStreams, decodeStringList, decodeTailFrame, definedOnly, describeCommonConfig, encodeCursor, encodePushRequest, entryToLogRecord, formatLabelSet, getLogging, initLogging, isIdempotentMethod, isRetryableStatus, isSensitiveField, isSensitiveHeader, isValidLabelName, logRecordByteSize, logRecordFromJson, logRecordToJson, mergeOptions, mergeStreams, msToDuration, nanosToDate, normalizeLabelName, optionalNanos, parseBool, parseDuration, parseInteger, parseLogRecord, parseRetryAfter, pinoLevelToSeverity, pinoLineToRecord, pollUntil, quoteLogQL, readCommonEnv, recordsToOtlpJson, recordsToStreams, redactError, redactFields, redactHeaders, redactSecretsInText, redactText, redactUrl, requestLogger, resolveCommonConfig, safeCall, safeLogger, secondsToDate, secretValues, serializeLogRecord, silentLogger, sleep, snappyCompress, stdoutLine, stringMap, tenantIdProblem, throwIfAborted, toAttrValue, toAttributes, toNanos, toOtlpValue, toSearchLogQL, validateCommonConfig, validateLabelName, validateLabels, winstonLevelToSeverity, withRequestId };
|
|
1460
|
+
export type { CallOptions, CardinalityGuardOptions, ClientInternals, ClientLogger, CommonConfig, CommonConfigOptions, CommonVendorEnv, Direction, EnvHit, EnvMap, ErrorClassifier, ErrorInfo, ErrorResponse, HeadersInput, Hooks, IndexOptions, InitLoggingOptions, KnownSecret, LabelsOptions, LiveTailOptions, LogConnection, LogConnector, LogFields, LogRecordJson, LoggingHandle, LokiBuildInfo, LokiClientShared, LokiConfigOptions, LokiDroppedEntry, LokiEntry, LokiEntryResult, LokiIndexStats, LokiLogClientOptions, LokiLogExporterOptions, LokiMatrixSeries, LokiPusher, LokiQueryResult, LokiQuerySource, LokiResultType, LokiSample, LokiStream, LokiStreamResult, LokiTail, LokiTailFrame, LokiTime, LokiVectorSample, MatchOperator, MergedEntry, NumericOperator, OtlpAnyValue, OtlpKeyValue, OtlpPushOptions, PinoTransportOptions, PollOptions, PushFormat, PushOptions, QueryOptions, QueryRangeOptions, QueryValue, RequestInfo, RequestLike, RequestLoggerOptions, RequestMiddleware, RequestOptions, ResponseInfo, ResponseLike, ResponseType, RetryPolicyOptions, SeriesOptions, TailCallbacks, TimeRangeOptions, TlsOptions, TransportOptions, TransportResponse, VolumeOptions, VolumeRangeOptions, WinstonInfo, WinstonTransportOptions };
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { L as LokiError, A as Attributes, a as LogRecord, b as AttrValue, c as LogClient, S as Severity, d as LogExporter, E as ExportOptions,
|
|
2
|
-
export {
|
|
1
|
+
import { L as LokiError, A as Attributes, a as LogRecord, b as AttrValue, c as LogClient, S as Severity, R as RedactionOptions, d as Logger, e as LogExporter, E as ExportOptions, f as ExportResult, B as BaseLogQueryClient, g as LogSearchOptions, h as LogSearchResult, T as TailOptions, i as TailHandle, H as HealthStatus, j as BatchingLogClientOptions, k as BatchingLogClient } from './query-BYQW0k9P.js';
|
|
2
|
+
export { l as AuthenticationError, m as BatchOptions, n as BatchProcessor, o as BatchStats, C as CancelledError, p as ConfigError, q as ConflictError, D as DEFAULT_BATCH_OPTIONS, r as DEFAULT_REDACT_KEYS, s as DropPolicy, t as DropReason, u as ErrorCode, v as ErrorDetails, w as LogInput, x as LogQueryClient, y as LogSink, z as LoggerOptions, N as NotFoundError, P as PermissionDeniedError, F as RateLimitError, G as RedactionProcessor, I as ResolvedBatchOptions, J as TimeoutError, U as UnavailableError, K as UnsupportedError, M as UnsupportedLogQueryClient, V as ValidationError, W as WaitForLogOptions, O as canonicalSeverity, Q as codeForStatus, X as errorForCode, Y as errorForStatus, Z as healthStatus, _ as isHealthyWord, $ as isLokiError, a0 as parseSeverity, a1 as pollTail, a2 as probeHealth, a3 as reasonForCode, a4 as resolveBatchOptions, a5 as severityText, a6 as waitForLog } from './query-BYQW0k9P.js';
|
|
3
3
|
import { Dispatcher } from 'undici';
|
|
4
4
|
import { Writable } from 'node:stream';
|
|
5
5
|
|
|
@@ -449,6 +449,12 @@ declare class HttpTransport {
|
|
|
449
449
|
constructor(options: TransportOptions);
|
|
450
450
|
/** Whether {@link close} was called. */
|
|
451
451
|
get closed(): boolean;
|
|
452
|
+
/**
|
|
453
|
+
* Throws `CancelledError` (`"<operation>: client is closed"`, not retryable) once {@link close}
|
|
454
|
+
* was called (SPEC §2.4). Requests check this themselves; service methods that send no request
|
|
455
|
+
* (cached reads, local helpers) call it first.
|
|
456
|
+
*/
|
|
457
|
+
ensureOpen(operation: string): void;
|
|
452
458
|
/** Builds the absolute URL for a path and query. */
|
|
453
459
|
buildUrl(path: string, query?: Readonly<Record<string, QueryValue>>): URL;
|
|
454
460
|
/** Redacts known secrets from a text (error messages, vendor text). */
|
|
@@ -479,13 +485,13 @@ declare class HttpTransport {
|
|
|
479
485
|
declare function redactSecretsInText(text: string): string;
|
|
480
486
|
|
|
481
487
|
/** Package version (kept in sync by release-please). */
|
|
482
|
-
declare const SDK_VERSION = "0.
|
|
488
|
+
declare const SDK_VERSION = "0.2.0";
|
|
483
489
|
/** Catalog key of the service (`grafana-loki`). */
|
|
484
490
|
declare const PACKAGE_KEY = "grafana-loki";
|
|
485
491
|
/** Language tag used in the User-Agent. */
|
|
486
492
|
declare const LANGUAGE = "typescript";
|
|
487
493
|
/** sdk-kit version this package was generated from. */
|
|
488
|
-
declare const SDK_KIT_VERSION = "0.
|
|
494
|
+
declare const SDK_KIT_VERSION = "0.3.0";
|
|
489
495
|
|
|
490
496
|
declare const INSPECT: unique symbol;
|
|
491
497
|
/** Longest tenant id Loki accepts (bytes). */
|
|
@@ -685,6 +691,118 @@ declare class WinstonTransport extends Writable {
|
|
|
685
691
|
close(): void;
|
|
686
692
|
}
|
|
687
693
|
|
|
694
|
+
/** Top-level stdout field: `"sdk"` = the SDK also exports the record (collector skips the line),
|
|
695
|
+
* `"sdk_failed"` = the SDK export failed or dropped it (collector ships the line). */
|
|
696
|
+
declare const LOG_SHIPPED_FIELD = "log_shipped";
|
|
697
|
+
/** What {@link connectLogClient} returns: the SDK transport and how to release it. */
|
|
698
|
+
interface LogConnection {
|
|
699
|
+
/** Batching log client of this package. */
|
|
700
|
+
logs: LogClient;
|
|
701
|
+
/** Flushes and closes the client (and the service client behind it). */
|
|
702
|
+
close(): Promise<void>;
|
|
703
|
+
}
|
|
704
|
+
/** Builds a {@link LogConnection} (service connector or a test seam); `undefined` = stdout only. */
|
|
705
|
+
type LogConnector = (options: {
|
|
706
|
+
resource: Attributes;
|
|
707
|
+
env: Readonly<Record<string, string | undefined>>;
|
|
708
|
+
/** Pass as `batch.onDrop`: records the SDK could not export are re-emitted on stdout. */
|
|
709
|
+
onDropped: (records: LogRecord[]) => void;
|
|
710
|
+
}) => LogConnection | undefined;
|
|
711
|
+
/** Options of {@link initLogging}. */
|
|
712
|
+
interface InitLoggingOptions {
|
|
713
|
+
/** `service.name` (default `GROW_SERVICE_NAME` > `OTEL_SERVICE_NAME` > `"unknown_service"`). */
|
|
714
|
+
service?: string;
|
|
715
|
+
/** Minimum level: trace|debug|info|warn|error|fatal (default `LOG_LEVEL` > `info`). */
|
|
716
|
+
level?: string;
|
|
717
|
+
/** Write JSON lines to stdout (default true). */
|
|
718
|
+
stdout?: boolean;
|
|
719
|
+
/** Ship through this package (default: `GROW_LOGGING_PROVIDER` equals the package key). */
|
|
720
|
+
ship?: boolean;
|
|
721
|
+
/** Extra redaction keys/patterns (default keys always apply). */
|
|
722
|
+
redaction?: RedactionOptions;
|
|
723
|
+
/** Environment (default `process.env`). */
|
|
724
|
+
env?: Readonly<Record<string, string | undefined>>;
|
|
725
|
+
/** Line writer (default `process.stdout`). Test seam. */
|
|
726
|
+
write?: (line: string) => void;
|
|
727
|
+
/** Connector override (tests, custom clients). Default: this package's `connectLogClient`. */
|
|
728
|
+
connect?: LogConnector;
|
|
729
|
+
}
|
|
730
|
+
/** Handle returned by {@link initLogging}. */
|
|
731
|
+
interface LoggingHandle {
|
|
732
|
+
/** The root logger (stdout JSON + SDK transport). */
|
|
733
|
+
logger: Logger;
|
|
734
|
+
/** The SDK log client when records are shipped, else `undefined`. */
|
|
735
|
+
logs: LogClient | undefined;
|
|
736
|
+
/** `true` when records are shipped through the SDK (stdout lines carry `log_shipped:"sdk"`). */
|
|
737
|
+
shipped: boolean;
|
|
738
|
+
/** `service.name` of every record. */
|
|
739
|
+
service: string;
|
|
740
|
+
/** Exports everything queued now (no-op without SDK transport). */
|
|
741
|
+
flush(timeoutMs?: number): Promise<void>;
|
|
742
|
+
/** Flushes and closes the SDK transport; idempotent. A new {@link initLogging} starts over. */
|
|
743
|
+
close(): Promise<void>;
|
|
744
|
+
/** Sends `message` (e.g. `foundation-canary-<token>`) through the SDK only and flushes. */
|
|
745
|
+
canary(message: string, attributes?: Attributes): Promise<boolean>;
|
|
746
|
+
/** A writable stream for `pino(…, stream)`: stdout copy + SDK transport. */
|
|
747
|
+
pinoStream(): Writable;
|
|
748
|
+
}
|
|
749
|
+
/** Runs `fn` with `requestId` attached to every record logged inside it. */
|
|
750
|
+
declare function withRequestId<T>(requestId: string, fn: () => T): T;
|
|
751
|
+
/** The request id of the current request ({@link withRequestId} / `requestLogger()`). */
|
|
752
|
+
declare function currentRequestId(): string | undefined;
|
|
753
|
+
/** The handle of the last {@link initLogging} call, if any. */
|
|
754
|
+
declare function getLogging(): LoggingHandle | undefined;
|
|
755
|
+
/**
|
|
756
|
+
* Converts one record into the stdout JSON line (flat, collector friendly). `marker` is written
|
|
757
|
+
* as the top-level {@link LOG_SHIPPED_FIELD} (`"sdk"`, `"sdk_failed"`); `undefined` omits it.
|
|
758
|
+
*/
|
|
759
|
+
declare function stdoutLine(record: LogRecord, marker?: string): string;
|
|
760
|
+
/**
|
|
761
|
+
* Initialises logging once per process: JSON lines on stdout (always, unless `stdout: false`) and,
|
|
762
|
+
* when `GROW_LOGGING_PROVIDER` names this package, the SDK transport built by `connectLogClient`
|
|
763
|
+
* from the package's own `GROW_<KEY>_*` variables (stdout lines are then marked
|
|
764
|
+
* `log_shipped:"sdk"`). Never throws for an unreachable logging service. Call it after
|
|
765
|
+
* `loadConfig()` of the secrets package.
|
|
766
|
+
*
|
|
767
|
+
* ```ts
|
|
768
|
+
* const { logger, flush } = initLogging({ service: "orders" });
|
|
769
|
+
* logger.info("started", { port: 3000 });
|
|
770
|
+
* ```
|
|
771
|
+
*/
|
|
772
|
+
declare function initLogging(opts?: InitLoggingOptions): LoggingHandle;
|
|
773
|
+
|
|
774
|
+
/** Minimal request shape (Node `IncomingMessage`, Express, Nest on Express). */
|
|
775
|
+
interface RequestLike {
|
|
776
|
+
method?: string;
|
|
777
|
+
url?: string;
|
|
778
|
+
originalUrl?: string;
|
|
779
|
+
headers: Record<string, string | string[] | undefined>;
|
|
780
|
+
}
|
|
781
|
+
/** Minimal response shape (Node `ServerResponse`). */
|
|
782
|
+
interface ResponseLike {
|
|
783
|
+
statusCode: number;
|
|
784
|
+
setHeader(name: string, value: string): unknown;
|
|
785
|
+
once(event: "finish" | "close", listener: () => void): unknown;
|
|
786
|
+
}
|
|
787
|
+
/** Options of {@link requestLogger}. */
|
|
788
|
+
interface RequestLoggerOptions {
|
|
789
|
+
/** Logger to use (default: the `initLogging()` logger). */
|
|
790
|
+
logger?: Logger;
|
|
791
|
+
/** Header that carries the request id (default `x-request-id`). */
|
|
792
|
+
header?: string;
|
|
793
|
+
/** Paths that are not logged (default `/health/live`, `/health/ready`). Prefix match. */
|
|
794
|
+
skip?: readonly string[];
|
|
795
|
+
}
|
|
796
|
+
/** Connect/Express style middleware. */
|
|
797
|
+
type RequestMiddleware = (req: RequestLike, res: ResponseLike, next: (err?: unknown) => void) => void;
|
|
798
|
+
/**
|
|
799
|
+
* Request middleware for Express, NestJS (`app.use(requestLogger())`) and plain Node `http`:
|
|
800
|
+
* reuses or creates the request id (`x-request-id`, echoed on the response), attaches it to every
|
|
801
|
+
* record logged while the request runs, and logs one `request completed` record with method,
|
|
802
|
+
* path, status and duration.
|
|
803
|
+
*/
|
|
804
|
+
declare function requestLogger(opts?: RequestLoggerOptions): RequestMiddleware;
|
|
805
|
+
|
|
688
806
|
/** Label names allowed by Loki (Prometheus rules). */
|
|
689
807
|
declare const LABEL_NAME_PATTERN: RegExp;
|
|
690
808
|
/**
|
|
@@ -1338,5 +1456,5 @@ declare function snappyCompress(data: Uint8Array): Uint8Array;
|
|
|
1338
1456
|
*/
|
|
1339
1457
|
declare function decodeRpcStatusMessage(bytes: Uint8Array): string | undefined;
|
|
1340
1458
|
|
|
1341
|
-
export { ALL_STREAMS_SELECTOR, AttrValue, Attributes, BaseLogQueryClient, BatchingLogClient, BatchingLogClientOptions, CardinalityGuard, DEFAULT_ALLOWED_LABELS, DEFAULT_REQUEST_ID_HEADERS, DEFAULT_TIMEOUTS, ENCODING_FLAGS_HEADER, EnvReader, ExportOptions, ExportResult, HealthStatus, HttpTransport, LABEL_NAME_PATTERN, LANGUAGE, LogClient, LogExporter, LogQL, LogRecord, LogSearchOptions, LogSearchResult, LokiClient, LokiConfig, LokiError, LokiLogExporter, LokiLogQueryClient, LokiOtlpExporter, MAX_QUERY_LIMIT, MAX_TENANT_ID_LENGTH, MAX_VENDOR_TEXT, MIN_SECRET_LENGTH, OTLP_SCOPE_NAME, PACKAGE_KEY, REDACTED, RESERVED_METADATA_KEYS, RetryPolicy, SDK_KIT_VERSION, SDK_VERSION, SENSITIVE_FIELD_PARTS, Secret, Severity, TENANT_HEADER, TailHandle, TailOptions, VENDOR_ENV, WinstonTransport, attrToString, createDispatcher, createPinoTransport, dateToNanos, decodeBuildInfo, decodeCursor, decodeEntry, decodeIndexStats, decodeQueryResult, decodeRpcStatusMessage, decodeSeries, decodeStreams, decodeStringList, decodeTailFrame, definedOnly, describeCommonConfig, encodeCursor, encodePushRequest, entryToLogRecord, formatLabelSet, isIdempotentMethod, isRetryableStatus, isSensitiveField, isSensitiveHeader, isValidLabelName, logRecordByteSize, logRecordFromJson, logRecordToJson, mergeOptions, mergeStreams, msToDuration, nanosToDate, normalizeLabelName, optionalNanos, parseBool, parseDuration, parseInteger, parseLogRecord, parseRetryAfter, pinoLevelToSeverity, pinoLineToRecord, pollUntil, quoteLogQL, readCommonEnv, recordsToOtlpJson, recordsToStreams, redactError, redactFields, redactHeaders, redactSecretsInText, redactText, redactUrl, resolveCommonConfig, safeCall, safeLogger, secondsToDate, secretValues, serializeLogRecord, silentLogger, sleep, snappyCompress, stringMap, tenantIdProblem, throwIfAborted, toAttrValue, toAttributes, toNanos, toOtlpValue, toSearchLogQL, validateCommonConfig, validateLabelName, validateLabels, winstonLevelToSeverity };
|
|
1342
|
-
export type { CallOptions, CardinalityGuardOptions, ClientInternals, ClientLogger, CommonConfig, CommonConfigOptions, CommonVendorEnv, Direction, EnvHit, EnvMap, ErrorClassifier, ErrorInfo, ErrorResponse, HeadersInput, Hooks, IndexOptions, KnownSecret, LabelsOptions, LiveTailOptions, LogFields, LogRecordJson, LokiBuildInfo, LokiClientShared, LokiConfigOptions, LokiDroppedEntry, LokiEntry, LokiEntryResult, LokiIndexStats, LokiLogClientOptions, LokiLogExporterOptions, LokiMatrixSeries, LokiPusher, LokiQueryResult, LokiQuerySource, LokiResultType, LokiSample, LokiStream, LokiStreamResult, LokiTail, LokiTailFrame, LokiTime, LokiVectorSample, MatchOperator, MergedEntry, NumericOperator, OtlpAnyValue, OtlpKeyValue, OtlpPushOptions, PinoTransportOptions, PollOptions, PushFormat, PushOptions, QueryOptions, QueryRangeOptions, QueryValue, RequestInfo, RequestOptions, ResponseInfo, ResponseType, RetryPolicyOptions, SeriesOptions, TailCallbacks, TimeRangeOptions, TlsOptions, TransportOptions, TransportResponse, VolumeOptions, VolumeRangeOptions, WinstonInfo, WinstonTransportOptions };
|
|
1459
|
+
export { ALL_STREAMS_SELECTOR, AttrValue, Attributes, BaseLogQueryClient, BatchingLogClient, BatchingLogClientOptions, CardinalityGuard, DEFAULT_ALLOWED_LABELS, DEFAULT_REQUEST_ID_HEADERS, DEFAULT_TIMEOUTS, ENCODING_FLAGS_HEADER, EnvReader, ExportOptions, ExportResult, HealthStatus, HttpTransport, LABEL_NAME_PATTERN, LANGUAGE, LOG_SHIPPED_FIELD, LogClient, LogExporter, LogQL, LogRecord, LogSearchOptions, LogSearchResult, Logger, LokiClient, LokiConfig, LokiError, LokiLogExporter, LokiLogQueryClient, LokiOtlpExporter, MAX_QUERY_LIMIT, MAX_TENANT_ID_LENGTH, MAX_VENDOR_TEXT, MIN_SECRET_LENGTH, OTLP_SCOPE_NAME, PACKAGE_KEY, REDACTED, RESERVED_METADATA_KEYS, RedactionOptions, RetryPolicy, SDK_KIT_VERSION, SDK_VERSION, SENSITIVE_FIELD_PARTS, Secret, Severity, TENANT_HEADER, TailHandle, TailOptions, VENDOR_ENV, WinstonTransport, attrToString, createDispatcher, createPinoTransport, currentRequestId, dateToNanos, decodeBuildInfo, decodeCursor, decodeEntry, decodeIndexStats, decodeQueryResult, decodeRpcStatusMessage, decodeSeries, decodeStreams, decodeStringList, decodeTailFrame, definedOnly, describeCommonConfig, encodeCursor, encodePushRequest, entryToLogRecord, formatLabelSet, getLogging, initLogging, isIdempotentMethod, isRetryableStatus, isSensitiveField, isSensitiveHeader, isValidLabelName, logRecordByteSize, logRecordFromJson, logRecordToJson, mergeOptions, mergeStreams, msToDuration, nanosToDate, normalizeLabelName, optionalNanos, parseBool, parseDuration, parseInteger, parseLogRecord, parseRetryAfter, pinoLevelToSeverity, pinoLineToRecord, pollUntil, quoteLogQL, readCommonEnv, recordsToOtlpJson, recordsToStreams, redactError, redactFields, redactHeaders, redactSecretsInText, redactText, redactUrl, requestLogger, resolveCommonConfig, safeCall, safeLogger, secondsToDate, secretValues, serializeLogRecord, silentLogger, sleep, snappyCompress, stdoutLine, stringMap, tenantIdProblem, throwIfAborted, toAttrValue, toAttributes, toNanos, toOtlpValue, toSearchLogQL, validateCommonConfig, validateLabelName, validateLabels, winstonLevelToSeverity, withRequestId };
|
|
1460
|
+
export type { CallOptions, CardinalityGuardOptions, ClientInternals, ClientLogger, CommonConfig, CommonConfigOptions, CommonVendorEnv, Direction, EnvHit, EnvMap, ErrorClassifier, ErrorInfo, ErrorResponse, HeadersInput, Hooks, IndexOptions, InitLoggingOptions, KnownSecret, LabelsOptions, LiveTailOptions, LogConnection, LogConnector, LogFields, LogRecordJson, LoggingHandle, LokiBuildInfo, LokiClientShared, LokiConfigOptions, LokiDroppedEntry, LokiEntry, LokiEntryResult, LokiIndexStats, LokiLogClientOptions, LokiLogExporterOptions, LokiMatrixSeries, LokiPusher, LokiQueryResult, LokiQuerySource, LokiResultType, LokiSample, LokiStream, LokiStreamResult, LokiTail, LokiTailFrame, LokiTime, LokiVectorSample, MatchOperator, MergedEntry, NumericOperator, OtlpAnyValue, OtlpKeyValue, OtlpPushOptions, PinoTransportOptions, PollOptions, PushFormat, PushOptions, QueryOptions, QueryRangeOptions, QueryValue, RequestInfo, RequestLike, RequestLoggerOptions, RequestMiddleware, RequestOptions, ResponseInfo, ResponseLike, ResponseType, RetryPolicyOptions, SeriesOptions, TailCallbacks, TimeRangeOptions, TlsOptions, TransportOptions, TransportResponse, VolumeOptions, VolumeRangeOptions, WinstonInfo, WinstonTransportOptions };
|