@bugsnag/core-performance
Advanced tools
Comparing version 2.8.1-alpha.0 to 2.9.0
import { BatchProcessor } from './batch-processor.js'; | ||
import { validateConfig } from './config.js'; | ||
import { validateConfig, schema } from './config.js'; | ||
import { TracePayloadEncoder } from './delivery.js'; | ||
@@ -24,2 +24,9 @@ import FixedProbabilityManager from './fixed-probability-manager.js'; | ||
const configuration = validateConfig(config, options.schema); | ||
// if using the default endpoint add the API key as a subdomain | ||
// e.g. convert URL https://otlp.bugsnag.com/v1/traces to URL https://<project_api_key>.otlp.bugsnag.com/v1/traces | ||
if (configuration.endpoint === schema.endpoint.defaultValue) { | ||
const endpointWithApiKeyInSubdomain = new URL(configuration.endpoint); | ||
endpointWithApiKeyInSubdomain.hostname = `${configuration.apiKey}.${endpointWithApiKeyInSubdomain.hostname}`; | ||
configuration.endpoint = endpointWithApiKeyInSubdomain.toString(); | ||
} | ||
// Correlate errors with span by monkey patching _notify on the error client | ||
@@ -26,0 +33,0 @@ // and utilizing the setTraceCorrelation method on the event |
@@ -42,3 +42,3 @@ import { SpanAttributes } from './attributes.js'; | ||
} | ||
const span = new SpanInternal(spanId, traceId, name, safeStartTime, attributes, parentSpanId); | ||
const span = new SpanInternal(spanId, traceId, name, safeStartTime, attributes, this.clock, parentSpanId); | ||
// don't track spans that are started while the app is backgrounded | ||
@@ -67,14 +67,19 @@ if (this.isInForeground) { | ||
endSpan(span, endTime, additionalAttributes) { | ||
// if the span doesn't exist here it shouldn't be processed | ||
if (!this.openSpans.delete(span)) { | ||
// only warn if the span has already been ended explicitly rather than | ||
// discarded by us | ||
if (!span.isValid()) { | ||
this.logger.warn('Attempted to end a Span which has already ended.'); | ||
} | ||
// remove the span from the context stack (this will also remove any invalid spans) | ||
this.spanContextStorage.pop(span); | ||
const untracked = !this.openSpans.delete(span); | ||
const isValidSpan = span.isValid(); | ||
// log a warning if the span is already invalid and is not being tracked | ||
if (untracked && !isValidSpan) { | ||
this.logger.warn('Attempted to end a Span which is no longer valid.'); | ||
} | ||
// spans should be discarded if: | ||
// - they are not tracked (i.e. discarded due to backgrounding) | ||
// - they are already invalid | ||
// - they have an explicit discard end time | ||
if (untracked || !isValidSpan || endTime === DISCARD_END_TIME) { | ||
// we still call end on the span so that it is no longer considered valid | ||
span.end(endTime, this.sampler.spanProbability); | ||
return; | ||
} | ||
// Discard marked spans | ||
if (endTime === DISCARD_END_TIME) | ||
return; | ||
// Set any additional attributes | ||
@@ -86,3 +91,2 @@ for (const [key, value] of Object.entries(additionalAttributes || {})) { | ||
const spanEnded = span.end(endTime, this.sampler.spanProbability); | ||
this.spanContextStorage.pop(span); | ||
if (this.sampler.sample(spanEnded)) { | ||
@@ -104,2 +108,10 @@ this.processor.add(spanEnded); | ||
isValid: () => span.isValid(), | ||
setAttribute: (name, value) => { | ||
if (typeof name !== 'string') { | ||
this.logger.warn(`Invalid attribute name, expected string, got ${typeof name}`); | ||
} | ||
else { | ||
span.setAttribute(name, value); | ||
} | ||
}, | ||
end: (endTime) => { | ||
@@ -106,0 +118,0 @@ const safeEndTime = timeToNumber(this.clock, endTime); |
@@ -5,2 +5,3 @@ import { SpanEvents } from './events.js'; | ||
const HOUR_IN_MILLISECONDS = 60 * 60 * 1000; | ||
function spanToJson(span, clock) { | ||
@@ -20,3 +21,3 @@ return { | ||
class SpanInternal { | ||
constructor(id, traceId, name, startTime, attributes, parentSpanId) { | ||
constructor(id, traceId, name, startTime, attributes, clock, parentSpanId) { | ||
this.kind = 3 /* Kind.Client */; // TODO: How do we define the initial Kind? | ||
@@ -31,2 +32,3 @@ this.events = new SpanEvents(); | ||
this.samplingRate = traceIdToSamplingRate(this.traceId); | ||
this.clock = clock; | ||
} | ||
@@ -64,3 +66,3 @@ addEvent(name, time) { | ||
isValid() { | ||
return this.endTime === undefined; | ||
return this.endTime === undefined && this.startTime > (this.clock.now() - HOUR_IN_MILLISECONDS); | ||
} | ||
@@ -67,0 +69,0 @@ } |
@@ -9,2 +9,3 @@ import type { SpanAttribute, SpanAttributes } from './attributes'; | ||
end: (endTime?: Time) => void; | ||
setAttribute: (name: string, value: SpanAttribute) => void; | ||
} | ||
@@ -50,5 +51,6 @@ export declare const enum Kind { | ||
private readonly attributes; | ||
private readonly clock; | ||
name: string; | ||
private endTime?; | ||
constructor(id: string, traceId: string, name: string, startTime: number, attributes: SpanAttributes, parentSpanId?: string); | ||
constructor(id: string, traceId: string, name: string, startTime: number, attributes: SpanAttributes, clock: Clock, parentSpanId?: string); | ||
addEvent(name: string, time: number): void; | ||
@@ -55,0 +57,0 @@ setAttribute(name: string, value: SpanAttribute): void; |
{ | ||
"name": "@bugsnag/core-performance", | ||
"version": "2.8.1-alpha.0", | ||
"version": "2.9.0", | ||
"description": "Core performance client", | ||
@@ -38,3 +38,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "904470ce3230f19ce28f858efe5cf6b0f18cecf1" | ||
"gitHead": "a618c85a96f0cce25d8348d1729d8e95e4cae1b6" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
95393
1676
0