Skip to content

Commit

Permalink
Merge pull request #3121 from OpenNeuroOrg/cli-version-sentry
Browse files Browse the repository at this point in the history
feat(cli): Migrate to Sentry from Elastic APM
  • Loading branch information
nellh authored Aug 12, 2024
2 parents 602df80 + fe69b72 commit b990ddb
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 1,173 deletions.
591 changes: 0 additions & 591 deletions .pnp.cjs

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions cli/openneuro.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
/**
* Entrypoint for OpenNeuro CLI
*/
import * as Sentry from "https://deno.land/x/sentry/index.mjs"
import lernaJson from "../lerna.json" with { type: "json" }
Sentry.init({
dsn:
"https://bf1156f5c83c236e0fcc4980535ebca4@o4507748938350592.ingest.us.sentry.io/4507748943200256",
release: `openneuro-cli@${lernaJson.version}`,
})
import { commandLine } from "./src/options.ts"

export async function main() {
Expand Down
4 changes: 2 additions & 2 deletions cli/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
LogLevelNames,
ValidatorOptions,
} from "./deps.ts"

import lernaJson from "../../lerna.json" with { type: "json" }
import { setupLogging } from "./logger.ts"
import { login } from "./commands/login.ts"
import { upload } from "./commands/upload.ts"
Expand All @@ -24,7 +24,7 @@ const openneuroCommand = new Command()
"OpenNeuro command line tools for uploading, downloading, or syncing datasets. See https://docs.openneuro.org for detailed guides.",
)
// TODO - Sync this with the node packages
.version("4.20.4")
.version(lernaJson.version)
.globalType("debugLevel", new EnumType(LogLevelNames))
.globalEnv("OPENNEURO_LOG=<type:debugLevel>", "Enable debug output.")
.globalAction(({ openneuroLog }) => {
Expand Down
1 change: 0 additions & 1 deletion packages/openneuro-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"bids-validator": "1.14.6",
"cli-progress": "^3.8.2",
"commander": "7.2.0",
"elastic-apm-node": "4.5.4",
"fetch-h2": "^3.0.2",
"graphql": "16.8.1",
"inquirer": "^5.2.0",
Expand Down
29 changes: 2 additions & 27 deletions packages/openneuro-cli/src/actions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable no-console */
import fs from "fs"
import inquirer from "inquirer"
import { apm } from "./apm.js"
import { getUrl, getUser, saveConfig } from "./config"
import { finishUpload, prepareUpload, uploadFiles, validation } from "./upload"
import { createDataset, getDatasetFiles } from "./datasets"
Expand Down Expand Up @@ -65,10 +64,8 @@ const uploadDataset = async (
affirmedConsent: null,
},
) => {
const apmTransaction = apm && apm.startTransaction("upload", "custom")
apmTransaction.addLabels({ datasetId })
const client = configuredClient()
await validation(dir, validatorOptions, apmTransaction)
await validation(dir, validatorOptions)
let remoteFiles = []
if (datasetId) {
// Check for dataset -> validation -> upload
Expand All @@ -86,27 +83,17 @@ const uploadDataset = async (
console.log(`"${datasetId}" created`)
remoteFiles = [] // New dataset has no remote files
}
const apmPrepareUploadSpan = apmTransaction &&
apmTransaction.startSpan("prepareUpload")
const preparedUpload = await prepareUpload(client, dir, {
datasetId,
remoteFiles,
})
apmPrepareUploadSpan.end()
if (preparedUpload) {
if (preparedUpload.files.length > 1) {
const apmUploadFilesSpan = apmTransaction &&
apmTransaction.startSpan("uploadFiles")
await uploadFiles(preparedUpload)
apmUploadFilesSpan && apmUploadFilesSpan.end()
const apmFinishUploadSpan = apmTransaction &&
apmTransaction.startSpan("finishUpload")
await finishUpload(client, preparedUpload.id)
apmUploadFilesSpan && apmFinishUploadSpan.end()
} else {
console.log("No files remaining to upload, exiting.")
}
apmTransaction && apmTransaction.end()
return datasetId
}
}
Expand Down Expand Up @@ -252,15 +239,6 @@ const promptTags = (snapshots) =>
* @param {Object} cmd
*/
export const download = (datasetId, destination, cmd) => {
const apmTransaction = apm.startTransaction(
`download:${datasetId}`,
"download",
)
const { sub } = getUser()
apmTransaction.addLabels({ datasetId, userId: sub })
if (cmd.snapshot) {
apmTransaction.addLabels({ snapshot: cmd.snapshot })
}
const client = configuredClient()
if (!cmd.draft && !cmd.snapshot) {
return getSnapshots(client)(datasetId).then(({ data }) => {
Expand All @@ -272,7 +250,6 @@ export const download = (datasetId, destination, cmd) => {
destination,
datasetId,
choices.tag,
apmTransaction,
client,
)
)
Expand All @@ -283,13 +260,11 @@ export const download = (datasetId, destination, cmd) => {
destination,
datasetId,
cmd.snapshot,
apmTransaction,
client,
)
} else {
return getDownload(destination, datasetId, null, apmTransaction, client)
return getDownload(destination, datasetId, null, client)
}
apmTransaction.end()
}

/**
Expand Down
23 changes: 0 additions & 23 deletions packages/openneuro-cli/src/apm.js

This file was deleted.

3 changes: 0 additions & 3 deletions packages/openneuro-cli/src/createDataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { gql } from "@apollo/client"
import inquirer from "inquirer"
import { getUrl } from "./config.js"
import { configuredClient } from "./configuredClient.js"
import { apm } from "./apm.js"

const CREATE_DATASET = gql`
mutation createDataset($affirmedDefaced: Boolean, $affirmedConsent: Boolean) {
Expand All @@ -17,7 +16,6 @@ const CREATE_DATASET = gql`
`

export const createDataset = async ({ affirmedDefaced, affirmedConsent }) => {
const apmTransaction = apm.startTransaction("createDataset", "custom")
const url = getUrl()
const client = configuredClient()
try {
Expand All @@ -35,7 +33,6 @@ export const createDataset = async ({ affirmedDefaced, affirmedConsent }) => {
'Dataset creation failed, you may need to rerun setup with "openneuro login" first',
)
}
apmTransaction.end()
}

export const create = () => {
Expand Down
11 changes: 0 additions & 11 deletions packages/openneuro-cli/src/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,11 @@ const handleFetchReject = (err) => {
* @param {string} destination Destination directory path
* @param {string} filename
* @param {string} fileUrl URL to download from
* @param {object} apmTransaction Active APM transaction (optional)
*/
export const downloadFile = async (
destination,
filename,
fileUrl,
apmTransaction,
downloadProgress,
) => {
try {
Expand All @@ -79,7 +77,6 @@ export const downloadFile = async (
downloadProgress.update(writeStream.bytesWritten)
})
stream.on("error", (err) => {
if (apmTransaction) apmTransaction.captureError(err)
reject(err)
})
})
Expand All @@ -95,7 +92,6 @@ export const downloadFile = async (
handleFetchReject(err)
}
} catch (err) {
if (apmTransaction) apmTransaction.captureError(err)
throw err
}
}
Expand All @@ -104,7 +100,6 @@ export const getDownload = async (
destination,
datasetId,
tag,
apmTransaction,
client,
treePath = "",
tree = null,
Expand All @@ -118,7 +113,6 @@ export const getDownload = async (
destination,
datasetId,
tag,
apmTransaction,
client,
downloadPath,
file.id,
Expand All @@ -135,16 +129,12 @@ export const getDownload = async (
})
if (testFile(destination, downloadPath, file.size)) {
// Now actually download
const apmDownload = apmTransaction.startSpan(
`download ${downloadPath}:${file.size}`,
)
downloadProgress.start(file.size, 0)
try {
await downloadFile(
destination,
downloadPath,
file.urls[file.urls.length - 1],
apmTransaction,
downloadProgress,
)
downloadProgress.update(file.size)
Expand All @@ -153,7 +143,6 @@ export const getDownload = async (
} finally {
downloadProgress.stop()
}
if (apmDownload) apmDownload.end()
} else {
downloadProgress.start(file.size, file.size)
downloadProgress.stop()
Expand Down
11 changes: 3 additions & 8 deletions packages/openneuro-cli/src/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,24 @@ const validatePromise = (dir, options = {}) => {
})
}

const fatalError = (err, apmSpan) => {
const fatalError = (err) => {
// eslint-disable-next-line no-console
console.error(err)
apmSpan.end()
process.exit(1)
}

/**
* Runs validation, logs summary or exits if an error is encountered
* @param {string} dir Directory to validate
* @param {object} validatorOptions Options passed to the validator
* @param {object} apmTransaction Elastic APM Transaction object
*/
export const validation = (dir, validatorOptions, apmTransaction) => {
const apmValidatePromiseSpan = apmTransaction &&
apmTransaction.startSpan("validatePromise")
export const validation = (dir, validatorOptions) => {
return validatePromise(dir, validatorOptions)
.then(function ({ summary }) {
// eslint-disable-next-line no-console
console.log(validate.consoleFormat.summary(summary))
apmValidatePromiseSpan.end()
})
.catch((err) => fatalError(err, apmValidatePromiseSpan))
.catch((err) => fatalError(err))
}

/**
Expand Down
Loading

0 comments on commit b990ddb

Please sign in to comment.