Add a profileSafe call #1

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
2 participants
@lynns

lynns commented Mar 27, 2013

When tracking api calls, it's not enough for us to just pass a name as an id to keep track of the profile call. This change will return a unique id
that can be used to close the correct profile call when there are multiple
profile calls with the same name open at once.

I'm not in love with the profileSafe name so if you think of something
better I'm good with that.

Add a profileSafe method so profiles with same id can be safely inter…
…leved.

When tracking api calls, it's not enough for us to just pass a name as an
id to keep track of the profile call.  This change will return an id
that can be used to close the correct profile call when there are multiple
profile calls with the same id.

I'm not in love with the `profileSafe` name so if you think of something
better I'm good with that.
@camshaft

This comment has been minimized.

Show comment Hide comment
@camshaft

camshaft Mar 27, 2013

Owner

So like i said in the docs, you'll want to create a new context for that metric:

var call1 = context.context({callId: 1}).profile('my-api-test-call')
  , call2 = context.context({callId: 2}).profile('my-api-test-call');
setTimeout(function() {
  call1.profile('my-api-test-call');
  str.should.match(/measure=my-api-test-call/);
  str.should.match(/callId=1/);

  call2.profile('my-api-test-call');
  str.should.match(/measure=my-api-test-call/);
  str.should.match(/callId=2/);
  done();
}, 50);
Owner

camshaft commented Mar 27, 2013

So like i said in the docs, you'll want to create a new context for that metric:

var call1 = context.context({callId: 1}).profile('my-api-test-call')
  , call2 = context.context({callId: 2}).profile('my-api-test-call');
setTimeout(function() {
  call1.profile('my-api-test-call');
  str.should.match(/measure=my-api-test-call/);
  str.should.match(/callId=1/);

  call2.profile('my-api-test-call');
  str.should.match(/measure=my-api-test-call/);
  str.should.match(/callId=2/);
  done();
}, 50);
@camshaft

This comment has been minimized.

Show comment Hide comment
@camshaft

camshaft Mar 28, 2013

Owner

you can also just get a blank context too:

var call1 = context.context().profile('my-api-test-call')
  , call2 = context.context().profile('my-api-test-call');
...
Owner

camshaft commented Mar 28, 2013

you can also just get a blank context too:

var call1 = context.context().profile('my-api-test-call')
  , call2 = context.context().profile('my-api-test-call');
...
@camshaft

This comment has been minimized.

Show comment Hide comment
@camshaft

camshaft Mar 28, 2013

Owner

k. i made a typo. You can't chain the .profile call because it returns the time. You'd have to do something like this:

var call1 = context.context({callId: 1})
  , call2 = context.context({callId: 2});

call1.profile('my-api-test-call');
call2.profile('my-api-test-call');

setTimeout(function() {
  call2.profile('my-api-test-call');
  str.should.match(/measure=my-api-test-call/);
  str.should.match(/callId=2/);

  call1.profile('my-api-test-call');
  str.should.match(/measure=my-api-test-call/);
  str.should.match(/callId=1/);
  done();
}, 50);
Owner

camshaft commented Mar 28, 2013

k. i made a typo. You can't chain the .profile call because it returns the time. You'd have to do something like this:

var call1 = context.context({callId: 1})
  , call2 = context.context({callId: 2});

call1.profile('my-api-test-call');
call2.profile('my-api-test-call');

setTimeout(function() {
  call2.profile('my-api-test-call');
  str.should.match(/measure=my-api-test-call/);
  str.should.match(/callId=2/);

  call1.profile('my-api-test-call');
  str.should.match(/measure=my-api-test-call/);
  str.should.match(/callId=1/);
  done();
}, 50);
@camshaft

This comment has been minimized.

Show comment Hide comment
@camshaft

camshaft Mar 28, 2013

Owner

I'm actually thinking this would be the best way; essentially it returns a function that you can once it's done. That way we don't have to deal with ids or new contexts.

var call1 = context.profile('my-api-test-call')
  , call2 = context.profile('my-api-test-call');

setTimeout(function() {
  call2({callId:2});
  str.should.match(/measure=my-api-test-call/);
  str.should.match(/callId=2/);

  call1({callId:1});
  str.should.match(/measure=my-api-test-call/);
  str.should.match(/callId=1/);
  done();
}, 50);
Owner

camshaft commented Mar 28, 2013

I'm actually thinking this would be the best way; essentially it returns a function that you can once it's done. That way we don't have to deal with ids or new contexts.

var call1 = context.profile('my-api-test-call')
  , call2 = context.profile('my-api-test-call');

setTimeout(function() {
  call2({callId:2});
  str.should.match(/measure=my-api-test-call/);
  str.should.match(/callId=2/);

  call1({callId:1});
  str.should.match(/measure=my-api-test-call/);
  str.should.match(/callId=1/);
  done();
}, 50);
@camshaft

This comment has been minimized.

Show comment Hide comment
@camshaft

camshaft Mar 28, 2013

Owner

K. I've implemented the above api so I'll go ahead and close this. If that doesn't work, feel free to open this up again.

Owner

camshaft commented Mar 28, 2013

K. I've implemented the above api so I'll go ahead and close this. If that doesn't work, feel free to open this up again.

@camshaft camshaft closed this Mar 28, 2013

@lynns

This comment has been minimized.

Show comment Hide comment
@lynns

lynns Mar 28, 2013

I like that. I'll start using it and let you know if I run into anything else.

lynns commented Mar 28, 2013

I like that. I'll start using it and let you know if I run into anything else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment