Skip to content
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

Revert "[RUMF-617] integrate tracing (#461)" #499

Merged
merged 2 commits into from
Aug 24, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions packages/core/src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { BuildEnv, BuildMode, Datacenter, INTAKE_SITE } from './init'
import { includes, ONE_KILO_BYTE, ONE_SECOND } from './utils'

export const DEFAULT_CONFIGURATION = {
allowedTracingOrigins: [] as Array<string | RegExp>,
isCollectingError: true,
maxErrorsByMinute: 3000,
maxInternalMonitoringMessagesPerPage: 15,
Expand Down Expand Up @@ -41,7 +40,6 @@ export interface UserConfiguration {
applicationId?: string
internalMonitoringApiKey?: string
isCollectingError?: boolean
allowedTracingOrigins?: Array<string | RegExp>
sampleRate?: number
resourceSampleRate?: number
datacenter?: Datacenter // deprecated
Expand All @@ -62,7 +60,6 @@ export interface UserConfiguration {
internalMonitoringEndpoint?: string
logsEndpoint?: string
rumEndpoint?: string
traceEndpoint?: string
}

interface ReplicaUserConfiguration {
Expand All @@ -76,10 +73,6 @@ export type Configuration = typeof DEFAULT_CONFIGURATION & {
traceEndpoint: string
internalMonitoringEndpoint?: string

service?: string
env?: string
version?: string

isEnabled: (feature: string) => boolean

// only on staging build mode
Expand All @@ -90,7 +83,6 @@ interface ReplicaConfiguration {
applicationId?: string
logsEndpoint: string
rumEndpoint: string
traceEndpoint: string
internalMonitoringEndpoint: string
}

Expand Down Expand Up @@ -123,15 +115,12 @@ export function buildConfiguration(userConfiguration: UserConfiguration, buildEn
: []

const configuration: Configuration = {
env: userConfiguration.env,
isEnabled: (feature: string) => {
return includes(enableExperimentalFeatures, feature)
},
logsEndpoint: getEndpoint('browser', transportConfiguration),
rumEndpoint: getEndpoint('rum', transportConfiguration),
service: userConfiguration.service,
traceEndpoint: getEndpoint('public-trace', transportConfiguration),
version: userConfiguration.version,
...DEFAULT_CONFIGURATION,
}
if (userConfiguration.internalMonitoringApiKey) {
Expand All @@ -142,10 +131,6 @@ export function buildConfiguration(userConfiguration: UserConfiguration, buildEn
)
}

if ('allowedTracingOrigins' in userConfiguration) {
configuration.allowedTracingOrigins = userConfiguration.allowedTracingOrigins!
}

if ('isCollectingError' in userConfiguration) {
configuration.isCollectingError = !!userConfiguration.isCollectingError
}
Expand All @@ -172,9 +157,6 @@ export function buildConfiguration(userConfiguration: UserConfiguration, buildEn
if (userConfiguration.rumEndpoint !== undefined) {
configuration.rumEndpoint = userConfiguration.rumEndpoint
}
if (userConfiguration.traceEndpoint !== undefined) {
configuration.traceEndpoint = userConfiguration.traceEndpoint
}
}

if (transportConfiguration.buildMode === BuildMode.STAGING) {
Expand All @@ -194,7 +176,6 @@ export function buildConfiguration(userConfiguration: UserConfiguration, buildEn
),
logsEndpoint: getEndpoint('browser', replicaTransportConfiguration),
rumEndpoint: getEndpoint('rum', replicaTransportConfiguration),
traceEndpoint: getEndpoint('public-trace', replicaTransportConfiguration),
}
}
}
Expand Down
35 changes: 10 additions & 25 deletions packages/core/src/fetchProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,18 @@ import { monitor } from './internalMonitoring'
import { computeStackTrace } from './tracekit'
import { normalizeUrl } from './urlPolyfill'

export interface FetchProxy<T extends FetchContext = FetchContext> {
beforeSend: (callback: (context: Partial<T>) => void) => void
onRequestComplete: (callback: (context: T) => void) => void
export interface FetchProxy {
beforeSend: (callback: (context: Partial<FetchContext>) => void) => void
onRequestComplete: (callback: (context: FetchContext) => void) => void
}

export interface FetchContext {
method: string
startTime: number
init?: RequestInit
duration: number
url: string
status: number
response: string
error?: {
name?: string
message: string
stack: string
}
responseType?: string

/**
Expand All @@ -31,10 +25,10 @@ export interface FetchContext {

let fetchProxySingleton: FetchProxy | undefined
let originalFetch: typeof window.fetch
const beforeSendCallbacks: Array<(fetch: Partial<FetchContext>) => void> = []
const onRequestCompleteCallbacks: Array<(fetch: FetchContext) => void> = []
const beforeSendCallbacks: Array<(xhr: Partial<FetchContext>) => void> = []
const onRequestCompleteCallbacks: Array<(xhr: FetchContext) => void> = []

export function startFetchProxy<T extends FetchContext = FetchContext>(): FetchProxy<T> {
export function startFetchProxy(): FetchProxy {
if (!fetchProxySingleton) {
proxyFetch()
fetchProxySingleton = {
Expand All @@ -46,7 +40,7 @@ export function startFetchProxy<T extends FetchContext = FetchContext>(): FetchP
},
}
}
return fetchProxySingleton as FetchProxy<T>
return fetchProxySingleton
}

export function resetFetchProxy() {
Expand All @@ -68,29 +62,20 @@ function proxyFetch() {
// tslint:disable promise-function-async
window.fetch = monitor(function(this: WindowOrWorkerGlobalScope['fetch'], input: RequestInfo, init?: RequestInit) {
const method = (init && init.method) || (typeof input === 'object' && input.method) || 'GET'
const url = normalizeUrl((typeof input === 'object' && input.url) || (input as string))
const startTime = performance.now()

const context: Partial<FetchContext> = {
init,
method,
startTime,
url,
}

const reportFetch = async (response: Response | Error) => {
context.duration = performance.now() - context.startTime!
context.url = normalizeUrl((typeof input === 'object' && input.url) || (input as string))

if ('stack' in response || response instanceof Error) {
const stackTrace = computeStackTrace(response)
const stackTraceString = toStackTraceString(stackTrace)
context.status = 0
context.error = {
message: stackTrace.message,
name: stackTrace.name,
stack: stackTraceString,
}
context.response = stackTraceString
context.response = toStackTraceString(computeStackTrace(response))

onRequestCompleteCallbacks.forEach((callback) => callback(context as FetchContext))
} else if ('status' in response) {
Expand All @@ -109,7 +94,7 @@ function proxyFetch() {
}
beforeSendCallbacks.forEach((callback) => callback(context))

const responsePromise = originalFetch.call(this, input, context.init)
const responsePromise = originalFetch.call(this, input, init)
responsePromise.then(monitor(reportFetch), monitor(reportFetch))
return responsePromise
})
Expand Down
16 changes: 8 additions & 8 deletions packages/core/src/xhrProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ interface BrowserXHR extends XMLHttpRequest {
_datadog_xhr: Partial<XhrContext>
}

export interface XhrProxy<T extends XhrContext = XhrContext> {
beforeSend: (callback: (context: Partial<T>, xhr: XMLHttpRequest) => void) => void
onRequestComplete: (callback: (context: T) => void) => void
export interface XhrProxy {
beforeSend: (callback: (context: Partial<XhrContext>) => void) => void
onRequestComplete: (callback: (context: XhrContext) => void) => void
}

export interface XhrContext {
Expand All @@ -25,24 +25,24 @@ export interface XhrContext {
}

let xhrProxySingleton: XhrProxy | undefined
const beforeSendCallbacks: Array<(context: Partial<XhrContext>, xhr: XMLHttpRequest) => void> = []
const beforeSendCallbacks: Array<(context: Partial<XhrContext>) => void> = []
const onRequestCompleteCallbacks: Array<(context: XhrContext) => void> = []
let originalXhrOpen: typeof XMLHttpRequest.prototype.open
let originalXhrSend: typeof XMLHttpRequest.prototype.send

export function startXhrProxy<T extends XhrContext = XhrContext>(): XhrProxy<T> {
export function startXhrProxy(): XhrProxy {
if (!xhrProxySingleton) {
proxyXhr()
xhrProxySingleton = {
beforeSend(callback: (context: Partial<XhrContext>, xhr: XMLHttpRequest) => void) {
beforeSend(callback: (context: Partial<XhrContext>) => void) {
beforeSendCallbacks.push(callback)
},
onRequestComplete(callback: (context: XhrContext) => void) {
onRequestCompleteCallbacks.push(callback)
},
}
}
return xhrProxySingleton as XhrProxy<T>
return xhrProxySingleton
}

export function resetXhrProxy() {
Expand Down Expand Up @@ -99,7 +99,7 @@ function proxyXhr() {

this.addEventListener('loadend', monitor(reportXhr))

beforeSendCallbacks.forEach((callback) => callback(this._datadog_xhr, this))
beforeSendCallbacks.forEach((callback) => callback(this._datadog_xhr))
}

return originalXhrSend.apply(this, arguments as any)
Expand Down
3 changes: 0 additions & 3 deletions packages/core/test/fetchProxy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ describe('fetch proxy', () => {
expect(request.url).toEqual(FAKE_URL)
expect(request.status).toEqual(0)
expect(request.response).toMatch(/Error: fetch error/)
expect(request.error!.name).toBe('Error')
expect(request.error!.message).toBe('fetch error')
expect(request.error!.stack).toMatch(/Error: fetch error/)
done()
})
})
Expand Down
2 changes: 0 additions & 2 deletions packages/rum/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ datadogRum.init({
- `service`: name of the corresponding service
- `env`: environment of the service
- `version`: version of the service
- `allowedTracingOrigins`: list of string or regexp of request origins in which to inject tracing headers

```
init(configuration: {
Expand All @@ -58,7 +57,6 @@ datadogRum.init({
service?: string,
env?: string,
version?: string,
allowedTracingOrigins?: Array<String|Regexp>,
})
```

Expand Down
Loading