Skip to content

Commit

Permalink
fix: re-enable apm in meteor
Browse files Browse the repository at this point in the history
uses a fork of `meteor-elastic-apm` until the PR is merged upstream. Meteor-Community-Packages/meteor-elastic-apm#77
  • Loading branch information
Julusian committed Feb 20, 2023
1 parent 757a183 commit 2f79e7e
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 63 deletions.
2 changes: 1 addition & 1 deletion meteor/.meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ meteorhacks:picker
ostrio:meteor-root
[email protected]

# kschingiz:meteor-elastic-apm
julusian:meteor-elastic-apm@2.5.2
2 changes: 2 additions & 0 deletions meteor/.meteor/versions
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ [email protected]
[email protected]
[email protected]
[email protected]
julusian:[email protected]
kschingiz:[email protected]
[email protected]
[email protected]
[email protected]
Expand Down
6 changes: 3 additions & 3 deletions meteor/__mocks__/_setupMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ jest.mock('meteor/reactive-var', (...args) => require('./reactive-var').setup(ar

jest.mock('meteor/meteorhacks:picker', (...args) => require('./meteorhacks-picker').setup(args), { virtual: true })
jest.mock('meteor/mdg:validated-method', (...args) => require('./validated-method').setup(args), { virtual: true })
// jest.mock('meteor/kschingiz:meteor-elastic-apm', (...args) => require('./meteor-elastic-apm').setup(args), {
// virtual: true,
// })
jest.mock('meteor/julusian:meteor-elastic-apm', (...args) => require('./meteor-elastic-apm').setup(args), {
virtual: true,
})

jest.mock('meteor/mongo', (...args) => require('./mongo').setup(args), { virtual: true })

Expand Down
25 changes: 1 addition & 24 deletions meteor/server/api/profiler.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,4 @@
/*
Note: meteor-elastic-apm has been temporarily disabled due to being incompatible Meteor 2.3
See https://github.com/Meteor-Community-Packages/meteor-elastic-apm/pull/61
So instead I've just added a temporary black-hole replacement for now /Johan Nyman 2022-01-18
*/
type StartSpan = (name: string) => undefined | { end: Function; addLabels: Function }
type StartTransaction = (
description: string,
name: string
) => undefined | { end: Function; addLabels: Function; startSpan: StartSpan }

const Agent: {
startSpan: StartSpan
startTransaction: StartTransaction
} = {
startSpan: (_name: string) => {
return undefined
},
startTransaction: (_descr: string, _name: string) => {
return undefined
},
}

// import Agent from 'meteor/kschingiz:meteor-elastic-apm'
import Agent from 'meteor/julusian:meteor-elastic-apm'

class Profiler {
private active: boolean = false
Expand Down
54 changes: 25 additions & 29 deletions meteor/server/coreSystem/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import { Studios } from '../../lib/collections/Studios'
import { getEnvLogLevel, logger, LogLevel, setLogLevel } from '../logging'
import { ShowStyleVariants } from '../../lib/collections/ShowStyleVariants'
const PackageInfo = require('../../package.json')
// import Agent from 'meteor/kschingiz:meteor-elastic-apm'
// import { profiler } from './api/profiler'
import Agent from 'meteor/julusian:meteor-elastic-apm'
import { profiler } from '../api/profiler'
import { TMP_TSR_VERSION } from '@sofie-automation/blueprints-integration'
import { getAbsolutePath } from '../lib'
import * as fs from 'fs/promises'
Expand Down Expand Up @@ -193,33 +193,29 @@ function startInstrumenting() {
}

// attempt init elastic APM

// Note: meteor-elastic-apm has been temporarily disabled due to being incompatible Meteor 2.3
// See https://github.com/Meteor-Community-Packages/meteor-elastic-apm/pull/61
//
// const system = getCoreSystem()
// const { APM_HOST, APM_SECRET, KIBANA_INDEX, APP_HOST } = process.env

// if (APM_HOST && system && system.apm) {
// logger.info(`APM agent starting up`)
// Agent.start({
// serviceName: KIBANA_INDEX || 'tv-automation-server-core',
// hostname: APP_HOST,
// serverUrl: APM_HOST,
// secretToken: APM_SECRET,
// active: system.apm.enabled,
// transactionSampleRate: system.apm.transactionSampleRate,
// disableMeteorInstrumentations: ['methods', 'http-out', 'session', 'async', 'metrics'],
// })
// profiler.setActive(system.apm.enabled || false)
// } else {
// logger.info(`APM agent inactive`)
// Agent.start({
// serviceName: 'tv-automation-server-core',
// active: false,
// disableMeteorInstrumentations: ['methods', 'http-out', 'session', 'async', 'metrics'],
// })
// }
const system = getCoreSystem()
const { APM_HOST, APM_SECRET, KIBANA_INDEX, APP_HOST } = process.env

if (APM_HOST && system && system.apm) {
logger.info(`APM agent starting up`)
Agent.start({
serviceName: KIBANA_INDEX || 'tv-automation-server-core',
hostname: APP_HOST,
serverUrl: APM_HOST,
secretToken: APM_SECRET,
active: system.apm.enabled,
transactionSampleRate: system.apm.transactionSampleRate,
disableMeteorInstrumentations: ['methods', 'http-out', 'session', 'async', 'metrics'],
})
profiler.setActive(system.apm.enabled || false)
} else {
logger.info(`APM agent inactive`)
Agent.start({
serviceName: 'tv-automation-server-core',
active: false,
disableMeteorInstrumentations: ['methods', 'http-out', 'session', 'async', 'metrics'],
})
}
}
function updateLoggerLevel(startup: boolean) {
if (Meteor.isTest) return // ignore this when running in tests
Expand Down
7 changes: 1 addition & 6 deletions meteor/server/typings/meteor-kschingiz-elastic-apm.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
* As they do not export any of the inner types, adding `disableMeteorInstrumentations` to `AgentConfigOptions` is not trivial without just copying it all
*/

/*
Note: meteor-elastic-apm has been temporarily disabled due to being incompatible Meteor 2.3
See https://github.com/Meteor-Community-Packages/meteor-elastic-apm/pull/61
declare module 'meteor/kschingiz:meteor-elastic-apm' {
declare module 'meteor/julusian:meteor-elastic-apm' {
/// <reference types="node" />

import { IncomingMessage, ServerResponse } from 'http'
Expand Down Expand Up @@ -357,4 +353,3 @@ declare module 'meteor/kschingiz:meteor-elastic-apm' {
type ErrorHandleFunction = (err: any, req: IncomingMessage, res: ServerResponse, next: NextFunction) => void
}
}
*/

0 comments on commit 2f79e7e

Please sign in to comment.