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

Support Meteor 3 #93

Open
wants to merge 339 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 92 commits
Commits
Show all changes
339 commits
Select commit Hold shift + click to select a range
932e476
metrics adjustments/checks
leonardoventurini Jun 2, 2023
8e6b657
remove unused code
leonardoventurini Jun 5, 2023
89d87e4
compute async and compute metrics based on intervals deduplication logic
leonardoventurini Jun 5, 2023
964930f
adjust function so it does not depend on the other
leonardoventurini Jun 6, 2023
601e0e2
fix async events being captured for meteor internals for methods
leonardoventurini Jun 7, 2023
d5a800b
fix async events being captured for meteor internals for subs
leonardoventurini Jun 8, 2023
382d7c1
pull request suggestions
leonardoventurini Jun 9, 2023
e71851e
add promise wrap
leonardoventurini Jun 9, 2023
76faba8
enable async events for other wraps
leonardoventurini Jun 9, 2023
c21f9b8
rename als to async as it also includes async hooks
leonardoventurini Jun 10, 2023
dc63f45
add initial documentation regarding async
leonardoventurini Jun 10, 2023
a3bcb14
add more information regarding awaits
leonardoventurini Jun 12, 2023
8eb8b58
add more information on then and catch
leonardoventurini Jun 13, 2023
a7d4594
add info regarding promiseResolve
leonardoventurini Jun 13, 2023
e17541c
pin node version to 18
leonardoventurini Jun 13, 2023
5c5045c
add experimental async playground
leonardoventurini Jun 13, 2023
81e0e5d
initial nested events for async events
leonardoventurini Jun 13, 2023
5af5f89
add info on the promise executor function
leonardoventurini Jun 13, 2023
f9affaf
explain promise executor init
leonardoventurini Jun 13, 2023
f687259
eliminate async events with duration not above 0
leonardoventurini Jun 14, 2023
ac944ba
fix wrappers appearing as async events
leonardoventurini Jun 14, 2023
4410d32
break down into smaller files
leonardoventurini Jun 15, 2023
fc3475c
add node options on tests
leonardoventurini Jun 15, 2023
893c06d
revert hijacking findOneAsync
leonardoventurini Jun 15, 2023
ead29ed
if no event then don't set store
leonardoventurini Jun 15, 2023
4d75ba3
remove package with dependency conflict
leonardoventurini Jun 16, 2023
57a9287
remove unused code
leonardoventurini Jun 16, 2023
a3e9d7b
add environment variable
leonardoventurini Jun 16, 2023
c898e2c
check of environment variable too in this case
leonardoventurini Jun 19, 2023
b6e8ca7
improve testing accounting for async events
leonardoventurini Jun 19, 2023
ff4b65f
improve event cleanup for tests and fix some tests
leonardoventurini Jun 20, 2023
3af4893
add cleanup command
leonardoventurini Jun 22, 2023
186c3ae
fix tests and other improvements
leonardoventurini Jun 22, 2023
4607644
detect resources which should be siblings
leonardoventurini Jun 23, 2023
a3d8242
this is not needed
leonardoventurini Jun 23, 2023
b6103a0
add base metrics
leonardoventurini Jun 27, 2023
1880904
add interval tree
leonardoventurini Jun 28, 2023
cfef5ce
fix testing issues and improve async event filtering
leonardoventurini Jun 28, 2023
2ea716a
fix tests and revert sibling logic
leonardoventurini Jun 29, 2023
f112ca9
add info to async readme
leonardoventurini Jul 3, 2023
aa255b1
remove direct event creation for async resources
leonardoventurini Jul 3, 2023
b706798
fix tests; remove tests for async events
leonardoventurini Jul 3, 2023
e61182c
simplify interval union
leonardoventurini Jul 4, 2023
ab0234d
fix metrics and remove unused code
leonardoventurini Jul 7, 2023
23d8f61
hardcode agent version
leonardoventurini Jul 7, 2023
6edc058
fix deprecation warning
leonardoventurini Sep 4, 2023
6dabd0d
upgrade package
leonardoventurini Sep 4, 2023
7b6dfef
adjust versions
leonardoventurini Sep 4, 2023
b8a3d2b
make it adaptive instead
leonardoventurini Sep 5, 2023
1ab906e
run tests on alpha 10
leonardoventurini Sep 8, 2023
733c0bd
test adjustments
leonardoventurini Sep 8, 2023
e11fa88
properly migrate webapp logic to new express impl
leonardoventurini Sep 8, 2023
b26f832
Merge branch 'master' into feature/fiberless
leonardoventurini Sep 8, 2023
7a43d27
remove .envrc
leonardoventurini Sep 13, 2023
672a593
support typescript eslint
leonardoventurini Sep 15, 2023
927cbf1
adjust versions
leonardoventurini Sep 18, 2023
aee8fb3
upgrade meteorx
leonardoventurini Sep 18, 2023
6c93a11
fix test for fetch
leonardoventurini Oct 24, 2023
2ffad86
remove version constraints
leonardoventurini Oct 24, 2023
11e8935
add alpha 16
leonardoventurini Oct 27, 2023
7874ca8
use core beta
leonardoventurini Oct 27, 2023
1a3cf08
Merge branch 'master' into feature/fiberless
leonardoventurini Oct 27, 2023
e73aaed
use correct path for core
leonardoventurini Oct 27, 2023
a969763
fix lint
leonardoventurini Oct 27, 2023
78ec864
move pretty log packages
leonardoventurini Oct 27, 2023
d1b4d43
test using meteor directly
leonardoventurini Oct 27, 2023
3f5319f
fix unknown release
leonardoventurini Oct 27, 2023
e0cc9df
test in console
leonardoventurini Oct 27, 2023
f8cd976
add async event capture using await detector
leonardoventurini Oct 30, 2023
1929a29
push wip
leonardoventurini Oct 31, 2023
c4a6016
not this one
leonardoventurini Oct 31, 2023
57a8b55
fix endAt test
leonardoventurini Nov 2, 2023
fcf1f67
fix undefined error
leonardoventurini Nov 2, 2023
851dddd
add proxy interceptor
leonardoventurini Nov 2, 2023
47cae27
wrap bind environment to ignore async events from it
leonardoventurini Nov 2, 2023
d5ec746
remove log
leonardoventurini Nov 2, 2023
44359a3
we are not nesting for now
leonardoventurini Nov 2, 2023
e8a6bce
revert gh workflow changes
leonardoventurini Nov 6, 2023
babf7b3
revert gh workflow changes
leonardoventurini Nov 6, 2023
4c88ab8
no need in using resources for calculating async and compute metrics
leonardoventurini Nov 6, 2023
51ee531
remove logs
leonardoventurini Nov 7, 2023
7c960c8
latest alpha
leonardoventurini Nov 7, 2023
6dfd3c9
remove file
leonardoventurini Nov 7, 2023
d012fe6
remove log
leonardoventurini Nov 7, 2023
745ca9d
simplify code
leonardoventurini Nov 7, 2023
b601847
allow app to crash if there is any error on startup
leonardoventurini Nov 7, 2023
b4b2576
events shouldn't be bundled in the client
leonardoventurini Nov 7, 2023
8a8963c
remove function
leonardoventurini Nov 7, 2023
91649cc
adjust formatting
leonardoventurini Nov 7, 2023
f528aeb
simplify test code
leonardoventurini Nov 7, 2023
9442258
rename email event
leonardoventurini Nov 7, 2023
7b67764
remove code
leonardoventurini Nov 7, 2023
ae72673
delete comment
leonardoventurini Nov 7, 2023
c5e4966
add function name to data
leonardoventurini Nov 7, 2023
ab37fdb
use detector ignore
leonardoventurini Nov 8, 2023
c3980f5
Merge branch 'feature/fiberless' into feature/async-events
leonardoventurini Nov 8, 2023
29e6ca9
fix lint
leonardoventurini Nov 8, 2023
a352455
add comment
leonardoventurini Nov 8, 2023
24e90bd
simplify compute and async metric calculation
leonardoventurini Nov 9, 2023
e463f9f
upgrade core
leonardoventurini Nov 9, 2023
9918e41
Merge pull request #104 from monti-apm/feature/async-events
zodern Nov 9, 2023
dba540b
Remove test-helpers
zodern Nov 9, 2023
89f4ec2
add compute events back
leonardoventurini Nov 10, 2023
e14f20c
Merge remote-tracking branch 'origin/feature/fiberless' into feature/…
leonardoventurini Nov 10, 2023
d2c36dd
remove dependency on accounts base
leonardoventurini Nov 10, 2023
37b434c
fix test
leonardoventurini Nov 10, 2023
c287ea9
simplify code
leonardoventurini Nov 10, 2023
f644936
use meteor alpha version
leonardoventurini Nov 10, 2023
f4cdb86
remove packages from the bundle
leonardoventurini Nov 10, 2023
f911b6f
adjust workflow
leonardoventurini Nov 10, 2023
25d52ec
adjust workflow
leonardoventurini Nov 10, 2023
4a14385
Small optimizations to tracer
zodern Nov 10, 2023
291ff50
Fix custom events not ending
zodern Nov 11, 2023
fb6213f
Fix async events not ending
zodern Nov 11, 2023
d3c8073
Small improvements to optimized trace size
zodern Nov 11, 2023
a466c90
Always store data when set
zodern Nov 11, 2023
122b59c
Fix using Monti.event outside of trace
zodern Nov 11, 2023
0dda848
Change order of arguments in Kadira.event
zodern Nov 11, 2023
43cd864
Document Monti.event
zodern Nov 11, 2023
cda42ff
Combine sync and async callbacks
zodern Nov 11, 2023
a4b9835
Remove async id's from built trace
zodern Nov 12, 2023
dc670f2
Let event handle generating stack
zodern Nov 12, 2023
05674f4
Combine method wrappers
zodern Nov 13, 2023
6a0f1c3
Optimize creating async events
zodern Nov 13, 2023
87f7cee
Remove runWithEvent
zodern Nov 13, 2023
3e05b68
revert line change
leonardoventurini Nov 13, 2023
866862d
fix sharing the same store
leonardoventurini Nov 13, 2023
7527562
add test back
leonardoventurini Nov 13, 2023
f1fa4f8
optimize noOfCachedDocs
leonardoventurini Nov 13, 2023
2e1709a
Fix lint errors
zodern Nov 13, 2023
3c4bef5
Force color in tests
zodern Nov 13, 2023
29f68e9
Merge pull request #105 from monti-apm/feature/fiberless-trace-adjust…
zodern Nov 13, 2023
e84e38b
Avoid mutating events when optimizing
zodern Nov 13, 2023
69c5238
Fix compute with force ended events
zodern Nov 13, 2023
98110d1
Add offset to efficiently store parallel events
zodern Nov 14, 2023
13890f0
Remove unused parentEvent
zodern Nov 14, 2023
1b1b438
Call fn directly in asyncEvent
zodern Nov 14, 2023
f2003d3
Fix tests
zodern Nov 14, 2023
4076285
Track compute at beginning of nested events
zodern Nov 14, 2023
cd9eda5
Adjust flaky tests
zodern Nov 14, 2023
76416b7
wrap _nextObjectPromise and add test
leonardoventurini Nov 14, 2023
7e223ec
Add test for offset accuracy
zodern Nov 14, 2023
5e8a1d4
Only count each ms once
zodern Nov 14, 2023
8f2d57e
Use nested events for metrics in place of custom event
zodern Nov 14, 2023
443e228
Improve flaky test
zodern Nov 14, 2023
f0fe6f0
Speed up test
zodern Nov 14, 2023
edc33ff
Ignore unhelpful async events
zodern Nov 14, 2023
04e2bf2
adjust test
leonardoventurini Nov 15, 2023
1b0dc4f
add await
leonardoventurini Nov 15, 2023
85ddff3
remove async wraps
leonardoventurini Nov 15, 2023
0e2f12c
simplify code
leonardoventurini Nov 15, 2023
53972f4
remove meta arg
leonardoventurini Nov 15, 2023
5ac8019
Merge pull request #106 from monti-apm/feature/fiberless-trace-adjust…
leonardoventurini Nov 16, 2023
3455ccb
use trace timestamp instead
leonardoventurini Nov 16, 2023
ba94381
fix for tests
leonardoventurini Nov 16, 2023
128e5d2
fix test
leonardoventurini Nov 16, 2023
eb860af
attempt to set var as empty
leonardoventurini Nov 16, 2023
a315926
set node env to test
leonardoventurini Nov 16, 2023
19d8d0b
try to upgrade actions
leonardoventurini Nov 16, 2023
ec31dc0
we need to set node env forcefully
leonardoventurini Nov 16, 2023
38e80e4
add log
leonardoventurini Nov 16, 2023
62d8860
v3.0.0-beta.2
zodern Nov 17, 2023
5976ead
add package versions reporting back
leonardoventurini Nov 18, 2023
d11a134
fix bind this error
leonardoventurini Nov 18, 2023
a779cb5
add zodern:types back
leonardoventurini Nov 18, 2023
b019aa3
fix webapp references
leonardoventurini Nov 18, 2023
2c309d5
revert test changes
leonardoventurini Nov 18, 2023
9f8bbba
bump alpha version
leonardoventurini Nov 18, 2023
d08dd1e
split into multiple lines
leonardoventurini Nov 19, 2023
2c1c300
remove unused option
leonardoventurini Nov 19, 2023
afbdc60
optimize id gen
leonardoventurini Nov 19, 2023
a8c3e9a
remove unused prop
leonardoventurini Nov 19, 2023
027cf6e
remove workaround as the bug is fixed
leonardoventurini Nov 19, 2023
d4f4eae
callbacks are not used anymore
leonardoventurini Nov 20, 2023
71b98b0
no need to be async
leonardoventurini Nov 20, 2023
348ac70
remove message
leonardoventurini Nov 20, 2023
5f326dc
this function is sync
leonardoventurini Nov 20, 2023
65a2ec7
Indicate traces from new tracer
zodern Nov 20, 2023
1c00442
v3.0.0-beta.3
zodern Nov 20, 2023
e5906ac
Re-add http and email deps
zodern Nov 20, 2023
bdc691a
Update @monti-apm/core
zodern Nov 20, 2023
8af4782
v3.0.0-beta.4
zodern Nov 20, 2023
17d00dc
Merge remote-tracking branch 'origin/feature/fiberless' into feature/…
leonardoventurini Nov 21, 2023
87d296a
remove unused deps
leonardoventurini Nov 21, 2023
ea2857a
remove async metric reference
leonardoventurini Nov 21, 2023
a9ba3b2
wrap webapp middleware
leonardoventurini Nov 22, 2023
b81dacb
fix: pass all tests on latest alpha - fix some flaky tests
renanccastro Jan 3, 2024
a5a831d
Merge branch 'master' into feature/fiberless
renanccastro Jan 4, 2024
788891a
fix: lint issues
renanccastro Jan 4, 2024
b424c61
feat: support async events on webapp
renanccastro Jan 8, 2024
419b515
fix: test
renanccastro Jan 8, 2024
8a88e15
feat: add tests for middleware resolving before next is called
renanccastro Jan 9, 2024
3d8c3ae
feat: track raw route names
renanccastro Jan 12, 2024
946dad6
fix: do not count as async time
renanccastro Jan 16, 2024
e5a3be9
feat: merge
renanccastro Jan 17, 2024
5d77869
fix: bump meteor version
renanccastro Jan 19, 2024
6f87901
Merge branch 'master' into feature/fiberless
renanccastro Jan 19, 2024
80b765b
fix: merge
renanccastro Jan 19, 2024
259d525
fix: lint
renanccastro Jan 19, 2024
eeb9f7d
Merge remote-tracking branch 'origin/master' into feature/fiberless
renanccastro Mar 8, 2024
3cded05
fix: merge issues
renanccastro Mar 12, 2024
5a8befd
fix: wait/waited on tests
renanccastro Mar 26, 2024
8aaef6c
Merge branch 'master' into feature/fiberless
renanccastro Mar 26, 2024
14bd189
fix: merge
renanccastro Mar 26, 2024
21f8e2d
fix: lint
renanccastro Mar 26, 2024
b9e6eca
fix: tests and flaky tests
renanccastro Mar 27, 2024
710db8e
Merge branch 'master' into feature/fiberless
renanccastro May 1, 2024
e1b14db
Merge branch 'master' into feature/fiberless
renanccastro May 1, 2024
21f382c
feat: support async redis-oplog
renanccastro May 15, 2024
3df9e0d
Merge branch 'master' into feature/fiberless
renanccastro May 15, 2024
8906fbb
Merge branch 'master' into feature/fiberless
renanccastro May 15, 2024
5830cf3
fix: tests
renanccastro May 17, 2024
50752ee
Merge remote-tracking branch 'origin/master' into feature/fiberless
renanccastro May 17, 2024
06df08a
fix: lint
renanccastro May 17, 2024
be8d7d3
fix: use rc version
renanccastro May 17, 2024
0ac4e7c
fix: package versions
renanccastro May 17, 2024
80460b2
fix: package versions
renanccastro May 17, 2024
6b685a7
fix: package versions
renanccastro May 17, 2024
3610579
fix: package versions
renanccastro May 17, 2024
5b88e6b
fix: package versions
renanccastro May 17, 2024
f63629f
feat: rc.1
renanccastro May 20, 2024
f7e7041
feat: rc.1
renanccastro May 21, 2024
e8f3799
Merge remote-tracking branch 'origin/master' into feature/fiberless
renanccastro Jun 21, 2024
f7a1686
fix: lint issues
renanccastro Jun 21, 2024
a0f6d1b
chore: bump rc version
renanccastro Jul 15, 2024
c637944
Merge remote-tracking branch 'origin/master' into feature/fiberless
renanccastro Jul 15, 2024
53381dc
chore: bump to rc.8
renanccastro Jul 15, 2024
e3d21f8
Remove unused log
zodern Jul 15, 2024
370998a
Improve no-console disable's
zodern Jul 15, 2024
fc5b4bc
v3.0.0-beta.5
zodern Jul 15, 2024
8e59cf1
Add version constraint for http package
zodern Jul 15, 2024
e11175a
chore: bump version to latest 3.0 release
renanccastro Jul 16, 2024
d247514
chore: bump version to latest 3.0 release
renanccastro Jul 16, 2024
fabd836
Update @monti-apm/core
zodern Oct 15, 2024
ecaad76
Update Meteor releases for testing
zodern Oct 15, 2024
7abaf48
Adjust flaky test
zodern Oct 15, 2024
cfa25ae
Fix meteor release
zodern Oct 15, 2024
70a7d5e
Clean await detector data after each method and publication
zodern Oct 15, 2024
87cc521
Revert "Clean await detector data after each method and publication"
zodern Oct 16, 2024
d690a3b
v3.0.0-beta.7
zodern Oct 16, 2024
bba00cc
Add version constraint to http package
zodern Oct 16, 2024
f360407
Add support for express 5
zodern Nov 6, 2024
cd6573d
Force colors in tests
zodern Nov 6, 2024
453323c
Fix http test
zodern Nov 6, 2024
291a8ad
Add 3.1-beta.0 to CI
zodern Nov 6, 2024
8b7ba2f
Fix formatting
zodern Nov 6, 2024
076e32a
v3.0.0-beta.8
zodern Nov 6, 2024
efe1615
Update @monti-apm/core to 2 beta.7
zodern Nov 26, 2024
795f17e
Fix proxy option
zodern Nov 26, 2024
60f7364
v3.0.0-beta.9
zodern Nov 26, 2024
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
18 changes: 18 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
# This is file is intended to store and document useful commands which cannot simply be added to the package.json scripts section.
#

export METEOR_CHECKOUT_BIN=~/Repositories/meteor/meteor/meteor

function @test-checkout {
# No longer needed in Meteor 3.0
# export DISABLE_FIBERS=1
# export IGNORE_ASYNC_PLUGIN=1
# export MONGO_OPLOG_URL=mongodb://localhost:3001/local
export METEOR_PACKAGE_DIRS=~/Repositories/monti-apm/monti-apm-agent/packages

# Overrides Meteor's default behavior
export FORCE_COLOR=true

arch -arm64 $METEOR_CHECKOUT_BIN test-packages ./ --raw-logs "$@"
}
23 changes: 2 additions & 21 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,8 @@ jobs:
fail-fast: false
matrix:
meteorRelease:
- '--release 1.4.4.6'
- '--release 1.5.4.1'
- '--release 1.6.0.1'
- '--release 1.7.0.5'
- '--release 1.8.1'
- '--release 1.8.3'
- '--release 1.9.1'
- '--release 1.10.2'
- '--release 1.11'
- '--release 1.12.1'
- '--release 2.1.1'
- '--release 2.2'
- '--release 2.3.2'
- '--release 2.4.1'
- '--release 2.5.6'
- '--release 2.6.1'
- '--release 2.7.3'
- '--release 2.8.2'
- '--release 2.9.0'
# Latest version
-
# Meteor 3 Alpha
- '--release 3.0-alpha.6'
steps:
- name: Checkout code
uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ smart.lock
versions.json
.idea
.eslintcache
.envrc
packages/
35 changes: 35 additions & 0 deletions lib/als/als.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import fs from 'fs';
import util from 'util';
import { AsyncLocalStorage } from 'node:async_hooks';
import crypto from 'crypto';

export const getId = () => crypto.randomUUID();

export const MontiAsyncStorage = new AsyncLocalStorage();
export const MontiEnvironmentVariable = new AsyncLocalStorage();

export const runWithALS = (
fn,
storage = MontiAsyncStorage,
store = { id: getId(), info: null, env: {}, activeEvent: null }
) => function (...args) {
return storage.run(store, () => fn.apply(this, args));
};

export const getStore = () => MontiAsyncStorage.getStore() ?? {};

export const getInfo = () => MontiAsyncStorage.getStore()?.info;

export const setActiveEvent = (event, store = MontiAsyncStorage.getStore()) => {
if (!store) return;

MontiAsyncStorage.enterWith({ ...store, activeEvent: event });
};

export const getActiveEvent = (store = MontiAsyncStorage.getStore()) => store?.activeEvent;

export const runWithEnvironment = (fn, store = new Map([['env', {}]])) => runWithALS(fn, MontiEnvironmentVariable, store);

export const debug = label => (...args) => {
fs.writeFileSync(1, `${util.format(label, ...args)}\n`, { flag: 'a' });
};
150 changes: 150 additions & 0 deletions lib/als/async-hook.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
import asyncHooks from 'async_hooks';
import { getActiveEvent, getInfo } from './als';
import { EventType } from '../constants';
import { Ntp } from '../ntp';
import { checkForNested } from '../tracer/tracer';
import { stackTrace } from '../utils';

const getResource = (asyncId) => {
if (!asyncId) return;

const info = getInfo();

if (!info) return;

return info.resources.get(asyncId);
};

export const isDescendantOf = (asyncId, parentAsyncId) => {
const resource = getResource(asyncId);

if (!resource) return false;

if (resource.triggerAsyncId === parentAsyncId) return true;

const parent = getResource(resource.triggerAsyncId);

if (!parent) return false;

return isDescendantOf(parent.asyncId, parentAsyncId);
};

export const getAncestryChainOfIds = (asyncId) => {
const resource = getResource(asyncId);

if (!resource) return [];

if (!resource.triggerAsyncId) return [asyncId];

const parent = getResource(resource.triggerAsyncId);

if (!parent) return [asyncId];

return [...getAncestryChainOfIds(parent.asyncId), asyncId];
};

export const getActiveEventResource = () => {
const activeEvent = getActiveEvent();

return getResource(activeEvent?.asyncId);
};

const captureStartTime = (asyncId) => {
const resource = getResource(asyncId);

if (!resource) return;

resource.startTime = Ntp._now();
};

const captureEndTime = (asyncId) => {
const resource = getResource(asyncId);
if (!resource) return;

// Some resources do not trigger before/after hooks.
if (!resource.startTime) {
leonardoventurini marked this conversation as resolved.
Show resolved Hide resolved
resource.startTime = resource.initAt;
}

resource.endTime = Ntp._now();
resource.duration = resource.endTime - resource.startTime;

const info = getInfo();

// We can ignore async events which take less than a millisecond for performance.
if (resource.duration === 0) return;
if (!info) return;

// Some events finish after the trace is already processed.
if (info.trace.isEventsProcessed) return;

const activeEvent = getActiveEvent();

const asyncEvent = {
leonardoventurini marked this conversation as resolved.
Show resolved Hide resolved
type: EventType.Async,
at: resource.startTime,
endAt: resource.endTime,
asyncId,
level: activeEvent?.level + 1 || 0,
};

if (activeEvent && !activeEvent.endAt) {
leonardoventurini marked this conversation as resolved.
Show resolved Hide resolved
checkForNested(activeEvent);
activeEvent.nested.push(asyncEvent);
} else {
info.trace.events.push(asyncEvent);
}
};

export const AsyncResourceType = {
PROMISE: 'PROMISE',
};

const hook = asyncHooks.createHook({
init (asyncId, type, triggerAsyncId) {
const info = getInfo();

if (!info) return;

// We don't want to capture anything other than promise resources.
if (type !== AsyncResourceType.PROMISE) return;

const activeEvent = getActiveEvent();
leonardoventurini marked this conversation as resolved.
Show resolved Hide resolved

if (activeEvent?.asyncId === asyncId) return;

const {trace} = info || {};

if (!trace) return;

info.resources = info.resources || new Map();

info.resources.set(asyncId, {
asyncId,
triggerAsyncId,
type,
initAt: Ntp._now(),
startTime: null,
endTime: null,
trace: stackTrace(),
leonardoventurini marked this conversation as resolved.
Show resolved Hide resolved
activeEvent,
});

const trigger = info.resources.get(triggerAsyncId);

if (trigger) {
trigger.children = trigger.children || [];
trigger.children.push(asyncId);
}
},

before: captureStartTime,
after: captureEndTime,
promiseResolve: captureEndTime,
leonardoventurini marked this conversation as resolved.
Show resolved Hide resolved
});

hook.enable();

process.once('beforeExit', function () {
hook.disable();
});
7 changes: 6 additions & 1 deletion lib/auto_connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ Kadira._connectWithSettings = function () {
* Previously there was two log messages (one for instrumentation,
* and another for connection), this way we merged both of them.
*/

console.log('Monti APM: Instrumentation started...');
leonardoventurini marked this conversation as resolved.
Show resolved Hide resolved

Kadira._startInstrumenting(function () {
Kadira._connectWithEnv();
Kadira._connectWithSettings();
});

console.log('Monti APM: Instrumentation completed');
leonardoventurini marked this conversation as resolved.
Show resolved Hide resolved
}).catch(console.error);
leonardoventurini marked this conversation as resolved.
Show resolved Hide resolved
8 changes: 2 additions & 6 deletions lib/common/unify.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,10 @@ Kadira.options = {};

Monti = Kadira;

if (Meteor.wrapAsync) {
Kadira._wrapAsync = Meteor.wrapAsync;
} else {
Kadira._wrapAsync = Meteor._wrapAsync;
}
Kadira.wrapAsync = Meteor.wrapAsync;

if (Meteor.isServer) {
const EventEmitter = Npm.require('events').EventEmitter;
const EventEmitter = require('events').EventEmitter;
leonardoventurini marked this conversation as resolved.
Show resolved Hide resolved
const eventBus = new EventEmitter();
eventBus.setMaxListeners(0);

Expand Down
11 changes: 11 additions & 0 deletions lib/common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ export function getClientArchVersion (arch) {
}
}

export function omit (obj, keys) {
return Object.keys(obj)
.filter(k => !keys.includes(k))
.reduce((a, k) => ({ ...a, [k]: obj[k] }), {});
}
leonardoventurini marked this conversation as resolved.
Show resolved Hide resolved

const createStackTrace = () => {
if (Error.captureStackTrace) {
let err = {};
Expand Down Expand Up @@ -93,6 +99,8 @@ export const getErrorParameters = function (args) {
* @returns {boolean} True if the object has set any data which is not `null`, `undefined` or an empty string.
*/
export const objectHasData = function (obj) {
if (!obj) return false;
leonardoventurini marked this conversation as resolved.
Show resolved Hide resolved

return Object.values(obj).some(val => ![null, undefined, ''].includes(val));
};

Expand Down Expand Up @@ -131,3 +139,6 @@ export const millisToHuman = function (milliseconds) {

return builder.join(' ');
};


export const isNumber = n => typeof n === 'number' && !isNaN(n);
12 changes: 12 additions & 0 deletions lib/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const EventType = {
Async: 'async',
Complete: 'complete',
Compute: 'compute',
Custom: 'custom',
DB: 'db',
Error: 'error',
FS: 'fs',
HTTP: 'http',
Start: 'start',
Wait: 'wait',
};
4 changes: 2 additions & 2 deletions lib/docsize_cache.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
let LRU = Npm.require('lru-cache');
let jsonStringify = Npm.require('json-stringify-safe');
let LRU = require('lru-cache');
let jsonStringify = require('json-stringify-safe');

export const DocSzCache = function (maxItems, maxValues) {
this.items = new LRU({max: maxItems});
Expand Down
Loading