Skip to content

Commit

Permalink
chore(gatsby): Convert utils/tracer/index to typescript (#22296)
Browse files Browse the repository at this point in the history
* chore(gatsby): Convert utils/tracer/index to typescript

* Fix to individual import.
  • Loading branch information
kawamataryo authored Mar 17, 2020
1 parent f8b7317 commit c3eccce
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
2 changes: 1 addition & 1 deletion packages/gatsby/src/commands/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { buildProductionBundle } from "./build-javascript"
const bootstrap = require(`../bootstrap`)
const apiRunnerNode = require(`../utils/api-runner-node`)
const { copyStaticDirs } = require(`../utils/get-static-dir`)
const { initTracer, stopTracer } = require(`../utils/tracer`)
import { initTracer, stopTracer } from "../utils/tracer"
const db = require(`../db`)
const signalExit = require(`signal-exit`)
const telemetry = require(`gatsby-telemetry`)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { slash } = require(`gatsby-core-utils`)
const path = require(`path`)
const opentracing = require(`opentracing`)
import { slash } from "gatsby-core-utils"
import path from "path"
import { Tracer, initGlobalTracer } from "opentracing"

let tracerProvider

Expand All @@ -13,28 +13,23 @@ let tracerProvider
* `stop` - Run any tracer cleanup required before the node.js process
* exits
*/
function initTracer(tracerFile) {
let tracer
export const initTracer = (tracerFile: string): Tracer => {
let tracer: Tracer
if (tracerFile) {
const resolvedPath = slash(path.resolve(tracerFile))
tracerProvider = require(resolvedPath)
tracer = tracerProvider.create()
} else {
tracer = new opentracing.Tracer() // Noop
tracer = new Tracer() // Noop
}

opentracing.initGlobalTracer(tracer)
initGlobalTracer(tracer)

return tracer
}

async function stopTracer() {
export const stopTracer = async (): Promise<void> => {
if (tracerProvider && tracerProvider.stop) {
await tracerProvider.stop()
}
}

module.exports = {
initTracer,
stopTracer,
}

0 comments on commit c3eccce

Please sign in to comment.