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

Multiple ServerTiming instances should not share label(s) #7

Open
dotnetCarpenter opened this issue Apr 16, 2021 · 0 comments
Open

Comments

@dotnetCarpenter
Copy link

I think it is confusing that each label has to be distinct across multiple instances of ServerTiming.

Steps to reproduce

'use strict'

const ServerTiming = require('servertiming')

function time (label, promise) {
	return new Promise ((resolve, reject) => {

		const timing = new ServerTiming()
		timing.startTimer (label)

		promise.then(value => {
			timing.stopTimer (label)
			resolve ([value, {"Server-Timing":timing.generateHeader()}])
		})

	})
}

function heavyComputation (value) {
	return new Promise ((resolve, reject) => {
		setTimeout (() => {
			resolve (value)
		}, 500)
	})
}

Promise.all([
	time('Multiple ServerTiming instances should not share labels', heavyComputation(1)),
	time('Multiple ServerTiming instances should not share labels', heavyComputation(2)),
	time('Multiple ServerTiming instances should not share labels', heavyComputation(3)),
])
.then(timings => {
	timings.map(([value, header]) => console.log(value, header['Server-Timing']))
})
.catch (console.error)

The above will output:

1 multiple-servertiming-instances-should-not-share-labels; dur=500.8789; desc="Multiple ServerTiming instances should not share labels"
2 multiple-servertiming-instances-should-not-share-labels; dur=0; desc="Multiple ServerTiming instances should not share labels"
3 multiple-servertiming-instances-should-not-share-labels; dur=0; desc="Multiple ServerTiming instances should not share labels"

Obviously the duration is not correct.

node-servertiming: 1.5.0
node: v14.16.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant