Skip to content

Commit

Permalink
fix(tracing): cleanup otel setup (#5446)
Browse files Browse the repository at this point in the history
* fix(tracing): cleanup otel setup in build

* fix(tracing): cleanup otel sdk setup

* chore: linting

* fix: workaround for tinybench support drop for node 14

* fix: workaround for tinybench support drop for node 14

* fix: workaround for tinybench support drop for node 14
  • Loading branch information
JGAntunes committed Jan 8, 2024
1 parent a623ef2 commit 2d10996
Show file tree
Hide file tree
Showing 23 changed files with 14,279 additions and 17,127 deletions.
30,743 changes: 14,170 additions & 16,573 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions packages/build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,18 @@
"license": "MIT",
"dependencies": {
"@bugsnag/js": "^7.0.0",
"@honeycombio/opentelemetry-node": "^0.5.0",
"@netlify/blobs": "^6.3.1",
"@netlify/cache-utils": "^5.1.5",
"@netlify/config": "^20.10.0",
"@netlify/edge-bundler": "10.1.3",
"@netlify/framework-info": "^9.8.10",
"@netlify/functions-utils": "^5.2.46",
"@netlify/git-utils": "^5.1.1",
"@netlify/opentelemetry-utils": "^1.0.0",
"@netlify/plugins-list": "^6.73.0",
"@netlify/run-utils": "^5.1.1",
"@netlify/zip-it-and-ship-it": "9.28.2",
"@opentelemetry/api": "^1.4.1",
"@opentelemetry/core": "^1.17.1",
"@opentelemetry/api": "~1.6.0",
"@sindresorhus/slugify": "^2.0.0",
"ansi-escapes": "^6.0.0",
"chalk": "^5.0.0",
Expand Down Expand Up @@ -126,6 +125,7 @@
},
"devDependencies": {
"@netlify/nock-udp": "^3.1.2",
"@opentelemetry/sdk-trace-base": "^1.18.1",
"@types/node": "^14.18.53",
"atob": "^2.1.2",
"ava": "^4.0.0",
Expand Down
8 changes: 3 additions & 5 deletions packages/build/src/core/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { reportStatuses } from '../status/report.js'
import { getDevSteps, getSteps } from '../steps/get.js'
import { runSteps } from '../steps/run_steps.js'
import { initTimers, measureDuration } from '../time/main.js'
import { startTracing } from '../tracing/main.js'

import { getConfigOpts, loadConfig } from './config.js'
import { getConstants } from './constants.js'
Expand All @@ -35,11 +34,10 @@ export const startBuild = function (flags: Partial<BuildFlags>) {
logBuildStart(logs)
}

const { bugsnagKey, tracingOpts, debug, systemLogFile, ...flagsA } = normalizeFlags(flags, logs)
const errorMonitor = startErrorMonitor({ flags: { tracingOpts, debug, systemLogFile, ...flagsA }, logs, bugsnagKey })
const rootTracingContext = startTracing(tracingOpts, getSystemLogger(logs, debug, systemLogFile))
const { bugsnagKey, debug, systemLogFile, ...flagsA } = normalizeFlags(flags, logs)
const errorMonitor = startErrorMonitor({ flags: { debug, systemLogFile, ...flagsA }, logs, bugsnagKey })

return { ...flagsA, rootTracingContext, debug, systemLogFile, errorMonitor, logs, timers }
return { ...flagsA, debug, systemLogFile, errorMonitor, logs, timers }
}

const tExecBuild = async function ({
Expand Down
59 changes: 0 additions & 59 deletions packages/build/src/core/flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,65 +195,6 @@ Default: false`,
describe: 'Statsd port',
hidden: true,
},
tracing: {
describe: 'Tracing related options',
hidden: true,
},
'tracing.enabled': {
boolean: true,
describe: 'Enable distributed tracing for build',
hidden: true,
},
'tracing.preloadingEnabled': {
boolean: true,
describe: 'Enable distributed tracing for build via module preloading, to be removed once fully rolled out',
hidden: true,
},
'tracing.apiKey': {
string: true,
describe: 'API Key for the tracing backend provider',
hidden: true,
},
'tracing.httpProtocol': {
string: true,
describe: 'Traces backend protocol. HTTP or HTTPS.',
hidden: true,
},
'tracing.host': {
string: true,
describe: 'Traces backend host',
hidden: true,
},
'tracing.port': {
number: true,
describe: 'Traces backend port',
hidden: true,
},
'tracing.traceId': {
string: true,
describe: 'Trace ID used to stitch the emited traces to',
hidden: true,
},
'tracing.parentSpanId': {
string: true,
describe: 'Parent Span ID used to stitch the root parent span to',
hidden: true,
},
'tracing.sampleRate': {
number: true,
describe: 'Trace sample rate for the given trace ID',
hidden: true,
},
'tracing.traceFlags': {
number: true,
describe: 'Trace flags containing the trace settings for the given trace ID',
hidden: true,
},
'tracing.baggageFilePath': {
string: true,
describe: '',
hidden: true,
},
offline: {
boolean: true,
describe: `Do not send requests to the Netlify API to retrieve site settings.
Expand Down
10 changes: 5 additions & 5 deletions packages/build/src/core/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { setMultiSpanAttributes, getGlobalContext } from '@netlify/opentelemetry-utils'
import { trace, context } from '@opentelemetry/api'

import { handleBuildError } from '../error/handle.js'
Expand All @@ -6,7 +7,7 @@ import { getSystemLogger } from '../log/logger.js'
import { logTimer, logBuildSuccess } from '../log/messages/core.js'
import { trackBuildComplete } from '../telemetry/main.js'
import { reportTimers } from '../time/report.js'
import { stopTracing, setMultiSpanAttributes, RootExecutionAttributes } from '../tracing/main.js'
import { RootExecutionAttributes } from '../tracing/main.js'

import { execBuild, startBuild } from './build.js'
import { reportMetrics } from './report_metrics.js'
Expand Down Expand Up @@ -41,7 +42,6 @@ export async function buildSite(flags: Partial<BuildFlags> = {}): Promise<{
telemetry,
buildId,
deployId,
rootTracingContext,
eventHandlers,
...flagsA
}: any = startBuild(flags)
Expand All @@ -55,7 +55,9 @@ export async function buildSite(flags: Partial<BuildFlags> = {}): Promise<{
'site.id': flagsA.siteId,
'build.info.primary_framework': framework,
}
const rootCtx = context.with(rootTracingContext, () => setMultiSpanAttributes(attributes))
// Gets the initial root context passed to the build process and adds a series of attributes we're going to use across
// the trace
const rootCtx = context.with(getGlobalContext(), () => setMultiSpanAttributes(attributes))

return await tracer.startActiveSpan('exec-build', {}, rootCtx, async (span) => {
try {
Expand Down Expand Up @@ -141,8 +143,6 @@ export async function buildSite(flags: Partial<BuildFlags> = {}): Promise<{
return { success, severityCode, logs }
} finally {
span.end()
// Ensure we flush the resulting spans
await stopTracing()
}
})
}
Expand Down
4 changes: 1 addition & 3 deletions packages/build/src/core/normalize_flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { logFlags } from '../log/messages/config.js'
import { removeFalsy } from '../utils/remove_falsy.js'

import { DEFAULT_FEATURE_FLAGS } from './feature_flags.js'
import type { BuildFlags, Mode, TestOptions, TracingOptions } from './types.js'
import type { BuildFlags, Mode, TestOptions } from './types.js'

const REQUIRE_MODE: Mode = 'require'
const DEFAULT_EDGE_FUNCTIONS_DIST = '.netlify/edge-functions-dist/'
Expand Down Expand Up @@ -43,7 +43,6 @@ export type ResolvedFlags = {
statsdOpts: { host?: number; port: number }
bugsnagKey?: string
systemLogFile?: number
tracingOpts: TracingOptions
}

/** Normalize CLI flags */
Expand All @@ -62,7 +61,6 @@ export const normalizeFlags = function (flags: Partial<BuildFlags>, logs): Resol
...rawFlags,
...telemetryFlag,
statsdOpts: { ...defaultFlags.statsd, ...rawFlags.statsd },
tracingOpts: { ...defaultFlags.tracing, ...rawFlags.tracing },
featureFlags: { ...defaultFlags.featureFlags, ...rawFlags.featureFlags },
}
const normalizedFlags = removeFalsy(mergedFlags) as any
Expand Down
20 changes: 0 additions & 20 deletions packages/build/src/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ export type BuildCLIFlags = {
/** The invoking service of netlify build */
mode: Mode
telemetry: boolean
/** Distributed tracing properties for this build*/
tracing: TracingOptions
/**
* Buffer output instead of printing it
* @default false
Expand Down Expand Up @@ -84,21 +82,3 @@ export type ErrorParam = {
childEnv?: any
netlifyConfig?: NetlifyConfig
}

export type TracingOptions = {
enabled: boolean
/* Tracing is enabled via module preloading, to be removed once we fully rolled it out */
preloadingEnabled: boolean
httpProtocol: string
host: string
port: number
/** API Key used for a dedicated trace provider */
apiKey: string
/** Sample rate being used for this trace, this allows for consistent probability sampling */
sampleRate: number
/** Properties of the root span and trace id used to stitch context */
traceId: string
traceFlags: number
parentSpanId: string
baggageFilePath: string
}
4 changes: 2 additions & 2 deletions packages/build/src/error/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
startClient,
validateStatsDOptions,
} from '../report/statsd.js'
import { addErrorToActiveSpan } from '../tracing/main.js'
import { addBuildErrorToActiveSpan } from '../tracing/main.js'

import { getErrorInfo } from './info.js'

Expand All @@ -24,7 +24,7 @@ export const reportError = async function (
statsdOpts: InputStatsDOptions,
framework?: string,
): Promise<void> {
addErrorToActiveSpan(error)
addBuildErrorToActiveSpan(error)
if (!validateStatsDOptions(statsdOpts)) {
return
}
Expand Down
6 changes: 4 additions & 2 deletions packages/build/src/steps/error.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { addEventToActiveSpan } from '@netlify/opentelemetry-utils'

import type { ErrorParam } from '../core/types.js'
import { cancelBuild } from '../error/cancel.js'
import { handleBuildError } from '../error/handle.js'
import { getFullErrorInfo, parseErrorInfo } from '../error/parse/parse.js'
import { serializeErrorStatus } from '../error/parse/serialize_status.js'
import { BuildError, isPluginLocation, PluginLocation, ErrorTypes } from '../error/types.js'
import { isSoftFailEvent } from '../plugins/events.js'
import { addErrorToActiveSpan, addEventToActiveSpan } from '../tracing/main.js'
import { addBuildErrorToActiveSpan } from '../tracing/main.js'

import { isTrustedPlugin } from './plugin.js'

Expand All @@ -32,7 +34,7 @@ export const handleStepError = function ({
debug,
testOpts,
}) {
addErrorToActiveSpan(newError)
addBuildErrorToActiveSpan(newError)
// Core steps do not report error statuses
if (coreStep !== undefined) {
return { newError }
Expand Down
3 changes: 2 additions & 1 deletion packages/build/src/steps/run_step.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { setMultiSpanAttributes } from '@netlify/opentelemetry-utils'
import { trace } from '@opentelemetry/api'

import { addMutableConstants } from '../core/constants.js'
import { logStepStart } from '../log/messages/steps.js'
import { runsAlsoOnBuildFailure, runsOnlyOnBuildFailure } from '../plugins/events.js'
import { normalizeTagName } from '../report/statsd.js'
import { measureDuration } from '../time/main.js'
import { setMultiSpanAttributes, StepExecutionAttributes } from '../tracing/main.js'
import { StepExecutionAttributes } from '../tracing/main.js'

import { fireCoreStep } from './core_step.js'
import { firePluginStep } from './plugin.js'
Expand Down

0 comments on commit 2d10996

Please sign in to comment.