-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add _experimental_longtaskNoStartSession
flag
#899
Changes from 1 commit
10ef10a
f6d3c67
8484616
dbd4663
3d95c5e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,15 +19,21 @@ | |
import { InstrumentationBase, InstrumentationConfig } from '@opentelemetry/instrumentation' | ||
|
||
import { VERSION } from './version' | ||
import { getCurrentSessionState } from './session' | ||
import { SplunkOtelWebConfig } from './types' | ||
|
||
const LONGTASK_PERFORMANCE_TYPE = 'longtask' | ||
const MODULE_NAME = 'splunk-longtask' | ||
|
||
export class SplunkLongTaskInstrumentation extends InstrumentationBase { | ||
private _longtaskObserver: PerformanceObserver | undefined | ||
|
||
constructor(config: InstrumentationConfig = {}) { | ||
private initOptions: SplunkOtelWebConfig | ||
|
||
constructor(config: InstrumentationConfig = {}, initOptions: SplunkOtelWebConfig) { | ||
super(MODULE_NAME, VERSION, Object.assign({}, config)) | ||
|
||
this.initOptions = initOptions | ||
} | ||
|
||
disable(): void { | ||
|
@@ -52,6 +58,16 @@ export class SplunkLongTaskInstrumentation extends InstrumentationBase { | |
init(): void {} | ||
|
||
private _createSpanFromEntry(entry: PerformanceEntry) { | ||
if ( | ||
!!this.initOptions._experimental_longtaskNoStartSession && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the core of the PR... if there is no session we do not spawn new one when this flag is set to true |
||
!getCurrentSessionState({ | ||
forceStoreRead: false, | ||
}) | ||
) { | ||
// session expired, we do not want to spawn new session from long tasks | ||
return | ||
} | ||
|
||
const span = this.tracer.startSpan(LONGTASK_PERFORMANCE_TYPE, { | ||
startTime: entry.startTime, | ||
}) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,27 +17,24 @@ | |
*/ | ||
|
||
import './polyfill-safari10' | ||
import { InstrumentationConfig, registerInstrumentations } from '@opentelemetry/instrumentation' | ||
import { registerInstrumentations } from '@opentelemetry/instrumentation' | ||
import { | ||
ConsoleSpanExporter, | ||
SimpleSpanProcessor, | ||
BatchSpanProcessor, | ||
ReadableSpan, | ||
SpanExporter, | ||
SpanProcessor, | ||
BufferConfig, | ||
AlwaysOffSampler, | ||
AlwaysOnSampler, | ||
ParentBasedSampler, | ||
} from '@opentelemetry/sdk-trace-base' | ||
import { WebTracerConfig } from '@opentelemetry/sdk-trace-web' | ||
import { Attributes, diag, DiagConsoleLogger, DiagLogLevel } from '@opentelemetry/api' | ||
import { SplunkDocumentLoadInstrumentation } from './SplunkDocumentLoadInstrumentation' | ||
import { SplunkXhrPlugin } from './SplunkXhrPlugin' | ||
import { SplunkFetchInstrumentation } from './SplunkFetchInstrumentation' | ||
import { | ||
SplunkUserInteractionInstrumentation, | ||
SplunkUserInteractionInstrumentationConfig, | ||
DEFAULT_AUTO_INSTRUMENTED_EVENTS, | ||
DEFAULT_AUTO_INSTRUMENTED_EVENT_NAMES, | ||
UserInteractionEventsConfig, | ||
|
@@ -46,163 +43,35 @@ import { SplunkExporterConfig } from './exporters/common' | |
import { SplunkZipkinExporter } from './exporters/zipkin' | ||
import { ERROR_INSTRUMENTATION_NAME, SplunkErrorInstrumentation } from './SplunkErrorInstrumentation' | ||
import { generateId, getPluginConfig } from './utils' | ||
import { getRumSessionId, initSessionTracking } from './session' | ||
import { getRumSessionId, initSessionTracking, updateSessionStatus } from './session' | ||
import { SplunkWebSocketInstrumentation } from './SplunkWebSocketInstrumentation' | ||
import { WebVitalsInstrumentationConfig, initWebVitals } from './webvitals' | ||
import { initWebVitals } from './webvitals' | ||
import { SplunkLongTaskInstrumentation } from './SplunkLongTaskInstrumentation' | ||
import { SplunkPageVisibilityInstrumentation } from './SplunkPageVisibilityInstrumentation' | ||
import { SplunkConnectivityInstrumentation } from './SplunkConnectivityInstrumentation' | ||
import { | ||
SplunkPostDocLoadResourceInstrumentation, | ||
SplunkPostDocLoadResourceInstrumentationConfig, | ||
} from './SplunkPostDocLoadResourceInstrumentation' | ||
import { SplunkPostDocLoadResourceInstrumentation } from './SplunkPostDocLoadResourceInstrumentation' | ||
import { SplunkWebTracerProvider } from './SplunkWebTracerProvider' | ||
import { FetchInstrumentationConfig } from '@opentelemetry/instrumentation-fetch' | ||
import { XMLHttpRequestInstrumentationConfig } from '@opentelemetry/instrumentation-xml-http-request' | ||
import { InternalEventTarget, SplunkOtelWebEventTarget } from './EventTarget' | ||
import { ContextManagerConfig, SplunkContextManager } from './SplunkContextManager' | ||
import { SplunkContextManager } from './SplunkContextManager' | ||
import { Resource, ResourceAttributes } from '@opentelemetry/resources' | ||
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions' | ||
import { SDK_INFO, _globalThis } from '@opentelemetry/core' | ||
import { VERSION } from './version' | ||
import { getSyntheticsRunId, SYNTHETICS_RUN_ID_ATTRIBUTE } from './synthetics' | ||
import { SplunkSpanAttributesProcessor } from './SplunkSpanAttributesProcessor' | ||
import { SessionBasedSampler } from './SessionBasedSampler' | ||
import { | ||
SocketIoClientInstrumentationConfig, | ||
SplunkSocketIoClientInstrumentation, | ||
} from './SplunkSocketIoClientInstrumentation' | ||
import { SplunkSocketIoClientInstrumentation } from './SplunkSocketIoClientInstrumentation' | ||
import { SplunkOTLPTraceExporter } from './exporters/otlp' | ||
import { registerGlobal, unregisterGlobal } from './global-utils' | ||
import { BrowserInstanceService } from './services/BrowserInstanceService' | ||
import { SessionId } from './types' | ||
import { SessionId } from './session' | ||
import { SplunkOtelWebConfig, SplunkOtelWebExporterOptions, SplunkOtelWebOptionsInstrumentations } from './types' | ||
|
||
export { SplunkExporterConfig } from './exporters/common' | ||
export { SplunkZipkinExporter } from './exporters/zipkin' | ||
export * from './SplunkWebTracerProvider' | ||
export * from './SessionBasedSampler' | ||
|
||
interface SplunkOtelWebOptionsInstrumentations { | ||
connectivity?: boolean | InstrumentationConfig | ||
document?: boolean | InstrumentationConfig | ||
errors?: boolean | ||
fetch?: boolean | FetchInstrumentationConfig | ||
interactions?: boolean | SplunkUserInteractionInstrumentationConfig | ||
longtask?: boolean | InstrumentationConfig | ||
postload?: boolean | SplunkPostDocLoadResourceInstrumentationConfig | ||
socketio?: boolean | SocketIoClientInstrumentationConfig | ||
visibility?: boolean | InstrumentationConfig | ||
websocket?: boolean | InstrumentationConfig | ||
webvitals?: boolean | WebVitalsInstrumentationConfig | ||
xhr?: boolean | XMLHttpRequestInstrumentationConfig | ||
} | ||
|
||
export interface SplunkOtelWebExporterOptions { | ||
/** | ||
* Allows remapping Span's attributes right before they're serialized. | ||
* One potential use case of this method is to remove PII from the attributes. | ||
*/ | ||
onAttributesSerializing?: (attributes: Attributes, span: ReadableSpan) => Attributes | ||
|
||
/** | ||
* Switch from zipkin to otlp for exporting | ||
*/ | ||
otlp?: boolean | ||
} | ||
|
||
export interface SplunkOtelWebConfig { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. moved to separate file to avoid circular dependency |
||
/** | ||
* If enabled, all spans are treated as activity and extend the duration of the session. Defaults to false. | ||
*/ | ||
_experimental_allSpansExtendSession?: boolean | ||
|
||
/** Allows http beacon urls */ | ||
allowInsecureBeacon?: boolean | ||
|
||
/** Application name | ||
* @deprecated Renamed to `applicationName` | ||
*/ | ||
app?: string | ||
|
||
/** Application name */ | ||
applicationName?: string | ||
|
||
/** Destination for the captured data */ | ||
beaconEndpoint?: string | ||
|
||
/** | ||
* Destination for the captured data | ||
* @deprecated Renamed to `beaconEndpoint`, or use realm | ||
*/ | ||
beaconUrl?: string | ||
|
||
/** Options for context manager */ | ||
context?: ContextManagerConfig | ||
|
||
/** Sets session cookie to this domain */ | ||
cookieDomain?: string | ||
|
||
/** Turns on/off internal debug logging */ | ||
debug?: boolean | ||
|
||
/** | ||
* Sets a value for the `environment` attribute (persists through calls to `setGlobalAttributes()`) | ||
* */ | ||
deploymentEnvironment?: string | ||
|
||
/** | ||
* Sets a value for the `environment` attribute (persists through calls to `setGlobalAttributes()`) | ||
* @deprecated Renamed to `deploymentEnvironment` | ||
*/ | ||
environment?: string | ||
|
||
/** Allows configuring how telemetry data is sent to the backend */ | ||
exporter?: SplunkOtelWebExporterOptions | ||
|
||
/** Sets attributes added to every Span. */ | ||
globalAttributes?: Attributes | ||
|
||
/** | ||
* Applies for XHR, Fetch and Websocket URLs. URLs that partially match any regex in ignoreUrls will not be traced. | ||
* In addition, URLs that are _exact matches_ of strings in ignoreUrls will also not be traced. | ||
* */ | ||
ignoreUrls?: Array<string | RegExp> | ||
|
||
/** Configuration for instrumentation modules. */ | ||
instrumentations?: SplunkOtelWebOptionsInstrumentations | ||
|
||
/** | ||
* The name of your organization’s realm. Automatically configures beaconUrl with correct URL | ||
*/ | ||
realm?: string | ||
|
||
/** | ||
* Publicly-visible rum access token value. Please do not paste any other access token or auth value into here, as this | ||
* will be visible to every user of your app | ||
*/ | ||
rumAccessToken?: string | ||
|
||
/** | ||
* Publicly-visible `rumAuth` value. Please do not paste any other access token or auth value into here, as this | ||
* will be visible to every user of your app | ||
* @deprecated Renamed to rumAccessToken | ||
*/ | ||
rumAuth?: string | ||
|
||
/** | ||
* Config options passed to web tracer | ||
*/ | ||
tracer?: WebTracerConfig | ||
|
||
/** Use local storage to save session ID instead of cookie */ | ||
useLocalStorage?: boolean | ||
|
||
/** | ||
* Sets a value for the 'app.version' attribute | ||
*/ | ||
version?: string | ||
} | ||
|
||
interface SplunkOtelWebConfigInternal extends SplunkOtelWebConfig { | ||
bufferSize?: number | ||
bufferTimeout?: number | ||
|
@@ -327,6 +196,11 @@ export interface SplunkOtelWebType extends SplunkOtelWebEventTarget { | |
*/ | ||
_internalInit: (options: Partial<SplunkOtelWebConfigInternal>) => void | ||
|
||
/* Used internally by the SplunkSessionRecorder - span from session can extend the session */ | ||
_internalOnExternalSpanCreated: () => void | ||
|
||
_processedOptions: SplunkOtelWebConfigInternal | null | ||
|
||
attributesProcessor?: SplunkSpanAttributesProcessor | ||
|
||
deinit: (force?: boolean) => void | ||
|
@@ -370,6 +244,8 @@ export const SplunkRum: SplunkOtelWebType = { | |
ParentBasedSampler, | ||
SessionBasedSampler, | ||
|
||
_processedOptions: null, | ||
|
||
get inited(): boolean { | ||
return inited | ||
}, | ||
|
@@ -421,6 +297,8 @@ export const SplunkRum: SplunkOtelWebType = { | |
}, | ||
) | ||
|
||
this._processedOptions = processedOptions | ||
|
||
if (processedOptions.realm) { | ||
if (!processedOptions.beaconEndpoint) { | ||
processedOptions.beaconEndpoint = getBeaconEndpointForRealm(processedOptions) | ||
|
@@ -487,8 +365,12 @@ export const SplunkRum: SplunkOtelWebType = { | |
const instrumentations = INSTRUMENTATIONS.map(({ Instrument, confKey, disable }) => { | ||
const pluginConf = getPluginConfig(processedOptions.instrumentations[confKey], pluginDefaults, disable) | ||
if (pluginConf) { | ||
// @ts-expect-error Can't mark in any way that processedOptions.instrumentations[confKey] is of specifc config type | ||
const instrumentation = new Instrument(pluginConf) | ||
const instrumentation = | ||
Instrument === SplunkLongTaskInstrumentation | ||
? new Instrument(pluginConf, options) | ||
: // @ts-expect-error Can't mark in any way that processedOptions.instrumentations[confKey] is of specifc config type | ||
new Instrument(pluginConf) | ||
|
||
if (confKey === ERROR_INSTRUMENTATION_NAME && instrumentation instanceof SplunkErrorInstrumentation) { | ||
_errorInstrumentation = instrumentation | ||
} | ||
|
@@ -633,6 +515,14 @@ export const SplunkRum: SplunkOtelWebType = { | |
_experimental_getSessionId() { | ||
return this.getSessionId() | ||
}, | ||
|
||
_internalOnExternalSpanCreated() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this gets called from session recorder - when span is created we extend expiration (inactivity) time of session |
||
if (!this._processedOptions) { | ||
return | ||
} | ||
|
||
updateSessionStatus({ forceStore: false, useLocalStorage: this._processedOptions.useLocalStorage ?? false }) | ||
}, | ||
} | ||
|
||
export default SplunkRum |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding it here just to be sure since it is possible that session recorder can have a different version than web agent