🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@posthog/core

Package Overview
Dependencies
Maintainers
22
Versions
153
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@posthog/core - npm Package Compare versions

Comparing version
1.35.3
to
1.35.4
+2
-1
dist/logs/index.d.ts

@@ -10,2 +10,3 @@ import { Logger } from '../types';

private readonly _waitForStoragePersist;
private readonly _scopeName?;
private _maxBufferSize;

@@ -24,3 +25,3 @@ private _maxQueueSize;

private _droppedWarned;
constructor(_instance: LogsHost, _config: ResolvedPostHogLogsConfig, _logger: Logger, _getContext: () => LogSdkContext, _onReady: (fn: () => void) => void, _waitForStoragePersist?: () => Promise<void>);
constructor(_instance: LogsHost, _config: ResolvedPostHogLogsConfig, _logger: Logger, _getContext: () => LogSdkContext, _onReady: (fn: () => void) => void, _waitForStoragePersist?: () => Promise<void>, _scopeName?: string | undefined);
/**

@@ -27,0 +28,0 @@ * Clears the flush timer and rate-cap state. The host owns the record queue

@@ -1,1 +0,1 @@

{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/logs/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAA4B,MAAM,UAAU,CAAA;AAE3D,OAAO,KAAK,EAAoB,iBAAiB,EAAE,aAAa,EAAE,QAAQ,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAA;AAKtH,qBAAa,WAAW;IAgCpB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAMzB,OAAO,CAAC,QAAQ,CAAC,sBAAsB;IAzCzC,OAAO,CAAC,cAAc,CAAQ;IAG9B,OAAO,CAAC,aAAa,CAAQ;IAC7B,OAAO,CAAC,gBAAgB,CAAQ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AM,YAAA;IAYtC;;;OAGG;IACH,KAAK,IAAI,IAAI;IAcb,WAAW,IAAI,IAAI;IAKnB,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,IAAI;IAqC5C;;;;;OAKG;IACH,OAAO,CAAC,cAAc;IAuBtB;;;;;;;;;;;;;;;;;;;OAmBG;IACH,OAAO,CAAC,eAAe;IAwBvB;;;;;;;;;OASG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;YAad,WAAW;YAuEX,oBAAoB;IAYlC,OAAO,CAAC,wBAAwB;IAIhC,OAAO,CAAC,QAAQ;IA+BhB,OAAO,CAAC,cAAc;IAatB,OAAO,CAAC,eAAe;IAKvB,OAAO,CAAC,iBAAiB;IAKzB;;;;;;;;;OASG;IACG,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAcjD;;;;;;;;;;;OAWG;IACG,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAoBxD,OAAO,CAAC,kBAAkB;IAqB1B,OAAO,CAAC,gBAAgB;CAMzB"}

@@ -34,3 +34,3 @@ "use strict";

class PostHogLogs {
constructor(_instance, _config, _logger, _getContext, _onReady, _waitForStoragePersist = ()=>Promise.resolve()){
constructor(_instance, _config, _logger, _getContext, _onReady, _waitForStoragePersist = ()=>Promise.resolve(), _scopeName){
this._instance = _instance;

@@ -42,2 +42,3 @@ this._config = _config;

this._waitForStoragePersist = _waitForStoragePersist;
this._scopeName = _scopeName;
this._flushPromise = null;

@@ -142,3 +143,3 @@ this._evictedSinceAdvance = 0;

const records = batch.map((e)=>e.record);
const payload = (0, external_logs_utils_js_namespaceObject.buildOtlpLogsPayload)(records, this._buildResourceAttributes(), this._instance.getLibraryId(), this._instance.getLibraryVersion());
const payload = (0, external_logs_utils_js_namespaceObject.buildOtlpLogsPayload)(records, this._buildResourceAttributes(), this._scopeName ?? this._instance.getLibraryId(), this._instance.getLibraryVersion());
const outcome = await this._instance._sendLogsBatch(payload);

@@ -145,0 +146,0 @@ if ('too-large' === outcome.kind && batch.length > 1) {

@@ -6,3 +6,3 @@ import { buildOtlpLogRecord, buildOtlpLogsPayload, buildResourceAttributes } from "./logs-utils.mjs";

class PostHogLogs {
constructor(_instance, _config, _logger, _getContext, _onReady, _waitForStoragePersist = ()=>Promise.resolve()){
constructor(_instance, _config, _logger, _getContext, _onReady, _waitForStoragePersist = ()=>Promise.resolve(), _scopeName){
this._instance = _instance;

@@ -14,2 +14,3 @@ this._config = _config;

this._waitForStoragePersist = _waitForStoragePersist;
this._scopeName = _scopeName;
this._flushPromise = null;

@@ -114,3 +115,3 @@ this._evictedSinceAdvance = 0;

const records = batch.map((e)=>e.record);
const payload = buildOtlpLogsPayload(records, this._buildResourceAttributes(), this._instance.getLibraryId(), this._instance.getLibraryVersion());
const payload = buildOtlpLogsPayload(records, this._buildResourceAttributes(), this._scopeName ?? this._instance.getLibraryId(), this._instance.getLibraryVersion());
const outcome = await this._instance._sendLogsBatch(payload);

@@ -117,0 +118,0 @@ if ('too-large' === outcome.kind && batch.length > 1) {

@@ -32,12 +32,12 @@ import type { CaptureLogOptions, LogAttributeValue, LogSeverityLevel, OtlpAnyValue, OtlpKeyValue, OtlpLogRecord, OtlpLogsPayload, OtlpSeverityText } from '@posthog/types';

*/
export declare function buildResourceAttributes(config: ResolvedPostHogLogsConfig, scopeName: string, scopeVersion: string): Record<string, LogAttributeValue>;
export declare function buildResourceAttributes(config: ResolvedPostHogLogsConfig, sdkName: string, sdkVersion: string): Record<string, LogAttributeValue>;
/**
* Wraps a list of records in the OTLP `resourceLogs` envelope.
*
* `scopeName` is the SDK package name (`posthog-js`, `posthog-react-native`,
* etc.). `scopeVersion` is the SDK semver. The server combines them into a
* single `instrumentation_scope` field (`{name}@{version}`) used for
* SDK-version-level attribution in queries and dashboards.
* `scopeName` is the OTLP instrumentation scope name (`web`/`console` for
* browser, or the SDK library ID for other platforms). `scopeVersion` is the
* SDK semver. The server combines them into a single `instrumentation_scope`
* field (`{name}@{version}`) used for attribution in queries and dashboards.
*/
export declare function buildOtlpLogsPayload(logRecords: OtlpLogRecord[], resourceAttributes: Record<string, LogAttributeValue>, scopeName: string, scopeVersion: string): OtlpLogsPayload;
//# sourceMappingURL=logs-utils.d.ts.map

@@ -1,1 +0,1 @@

{"version":3,"file":"logs-utils.d.ts","sourceRoot":"","sources":["../../src/logs/logs-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,eAAe,EAEf,gBAAgB,EACjB,MAAM,gBAAgB,CAAA;AACvB,OAAO,KAAK,EAAE,aAAa,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAA;AAkBvE,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,gBAAgB,GAAG,gBAAgB,CAE7E;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,gBAAgB,GAAG,MAAM,CAErE;AAMD,wBAAgB,cAAc,CAAC,KAAK,EAAE,iBAAiB,GAAG,YAAY,CAiCrE;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,GAAG,YAAY,EAAE,CAU3F;AAiBD;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,aAAa,GAAG,aAAa,CAmDvG;AAMD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,yBAAyB,EACjC,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,MAAM,GACnB,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CASnC;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAClC,UAAU,EAAE,aAAa,EAAE,EAC3B,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,EACrD,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,MAAM,GACnB,eAAe,CAcjB"}
{"version":3,"file":"logs-utils.d.ts","sourceRoot":"","sources":["../../src/logs/logs-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,eAAe,EAEf,gBAAgB,EACjB,MAAM,gBAAgB,CAAA;AACvB,OAAO,KAAK,EAAE,aAAa,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAA;AAkBvE,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,gBAAgB,GAAG,gBAAgB,CAE7E;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,gBAAgB,GAAG,MAAM,CAErE;AAMD,wBAAgB,cAAc,CAAC,KAAK,EAAE,iBAAiB,GAAG,YAAY,CAiCrE;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,GAAG,YAAY,EAAE,CAU3F;AAiBD;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,aAAa,GAAG,aAAa,CAmDvG;AAMD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,yBAAyB,EACjC,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,GACjB,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CASnC;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAClC,UAAU,EAAE,aAAa,EAAE,EAC3B,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,EACrD,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,MAAM,GACnB,eAAe,CAcjB"}

@@ -146,3 +146,3 @@ "use strict";

}
function buildResourceAttributes(config, scopeName, scopeVersion) {
function buildResourceAttributes(config, sdkName, sdkVersion) {
return {

@@ -157,4 +157,4 @@ ...config.resourceAttributes,

},
'telemetry.sdk.name': scopeName,
'telemetry.sdk.version': scopeVersion
'telemetry.sdk.name': sdkName,
'telemetry.sdk.version': sdkVersion
};

@@ -161,0 +161,0 @@ }

@@ -112,3 +112,3 @@ import { isArray, isBoolean, isNull, isUndefined } from "../utils/index.mjs";

}
function buildResourceAttributes(config, scopeName, scopeVersion) {
function buildResourceAttributes(config, sdkName, sdkVersion) {
return {

@@ -123,4 +123,4 @@ ...config.resourceAttributes,

},
'telemetry.sdk.name': scopeName,
'telemetry.sdk.version': scopeVersion
'telemetry.sdk.name': sdkName,
'telemetry.sdk.version': sdkVersion
};

@@ -127,0 +127,0 @@ }

{
"name": "@posthog/core",
"version": "1.35.3",
"version": "1.35.4",
"bugs": {

@@ -5,0 +5,0 @@ "url": "https://github.com/PostHog/posthog-js/issues"

@@ -459,2 +459,28 @@ import { PostHogPersistedProperty } from '../types'

it('uses the scopeName constructor param as the OTLP scope name', async () => {
jest.useFakeTimers()
const logs = new PostHogLogs(
mockInstance,
resolveForTest(),
logger,
getContextFor(mockInstance),
immediateOnReady,
() => Promise.resolve(),
'console'
)
logs.captureLog({ body: 'test' })
await logs.flush()
const payload = mockInstance._sendLogsBatch.mock.calls[0][0]
const scope = payload.resourceLogs[0].scopeLogs[0].scope
// scopeName param overrides getLibraryId(); telemetry.sdk.name still uses getLibraryId().
expect(scope.name).toBe('console')
const resourceAttrs = Object.fromEntries(
payload.resourceLogs[0].resource.attributes.map((a: any) => [a.key, a.value])
)
expect(resourceAttrs['telemetry.sdk.name']).toEqual({ stringValue: 'posthog-core-tests' })
jest.useRealTimers()
})
it('defaults service.name to "unknown_service" when not configured', async () => {

@@ -461,0 +487,0 @@ const logs = new PostHogLogs(

@@ -52,3 +52,7 @@ import type { LogAttributeValue } from '@posthog/types'

// wires this to its dedicated `_logsStorage.waitForPersist()`.
private readonly _waitForStoragePersist: () => Promise<void> = () => Promise.resolve()
private readonly _waitForStoragePersist: () => Promise<void> = () => Promise.resolve(),
// OTLP instrumentation scope name. Overrides the `getLibraryId()` fallback
// so a host can label a specific capture stream (e.g. 'console' for browser
// console auto-capture). Defaults to `getLibraryId()` when omitted.
private readonly _scopeName?: string
) {

@@ -246,3 +250,3 @@ this._maxBufferSize = _config.maxBufferSize

this._buildResourceAttributes(),
this._instance.getLibraryId(),
this._scopeName ?? this._instance.getLibraryId(),
this._instance.getLibraryVersion()

@@ -249,0 +253,0 @@ )

@@ -187,4 +187,4 @@ import type {

config: ResolvedPostHogLogsConfig,
scopeName: string,
scopeVersion: string
sdkName: string,
sdkVersion: string
): Record<string, LogAttributeValue> {

@@ -196,4 +196,4 @@ return {

...(config.serviceVersion && { 'service.version': config.serviceVersion }),
'telemetry.sdk.name': scopeName,
'telemetry.sdk.version': scopeVersion,
'telemetry.sdk.name': sdkName,
'telemetry.sdk.version': sdkVersion,
}

@@ -205,6 +205,6 @@ }

*
* `scopeName` is the SDK package name (`posthog-js`, `posthog-react-native`,
* etc.). `scopeVersion` is the SDK semver. The server combines them into a
* single `instrumentation_scope` field (`{name}@{version}`) used for
* SDK-version-level attribution in queries and dashboards.
* `scopeName` is the OTLP instrumentation scope name (`web`/`console` for
* browser, or the SDK library ID for other platforms). `scopeVersion` is the
* SDK semver. The server combines them into a single `instrumentation_scope`
* field (`{name}@{version}`) used for attribution in queries and dashboards.
*/

@@ -211,0 +211,0 @@ export function buildOtlpLogsPayload(