Skip to content
This repository has been archived by the owner on Dec 8, 2018. It is now read-only.

Add timestamp and duration to Diagnostics Source events #261

Closed

Conversation

avanderhoorn
Copy link
Member

Given the precedence of what we have here aspnet/Hosting#543 I'm adding timestamp data to these events - this ensures that everyone is working from the same base data when talking timings.

In addition, I'm adding duration to the finish events so that consumers only have to subscribe to finish events in order to determine what the duration for a given piece of middleware is. This change is localized to the scope of code where we know that we have listeners interested in the result and hence isn't on the primary execution path.

@dnfclas
Copy link

dnfclas commented Mar 23, 2016

Hi @avanderhoorn, I'm your friendly neighborhood .NET Foundation Pull Request Bot (You can call me DNFBOT). Thanks for your contribution!
You've already signed the contribution license agreement. Thanks!

The agreement was validated by .NET Foundation and real humans are currently evaluating your PR.

TTYL, DNFBOT;

@avanderhoorn avanderhoorn changed the title Adds timestamp in accordance with hosting example, as well as duration Add timestamp and duration to Diagnostics Source events Mar 24, 2016
@Tratcher
Copy link
Member

@lodejard @rynowak @Eilon

if (_diagnostics.IsEnabled("Microsoft.AspNetCore.MiddlewareAnalysis.MiddlewareStarting"))
{
_diagnostics.Write("Microsoft.AspNetCore.MiddlewareAnalysis.MiddlewareStarting", new { name = _middlewareName, httpContext = httpContext, instanceId = _instanceId });
startTimestamp = Stopwatch.GetTimestamp();
_diagnostics.Write("Microsoft.AspNetCore.MiddlewareAnalysis.MiddlewareStarting", new { name = _middlewareName, httpContext = httpContext, instanceId = _instanceId, timestamp = startTimestamp });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines are getting a tad long - can you wrap them like:

_diagnostics.Write(
    "Microsoft.AspNetCore.MiddlewareAnalysis.MiddlewareStarting",
    new
    {
        name = _middlewareName,
        httpContext = httpContext,
        instanceId = _instanceId,
        timestamp = startTimestamp, // and include this trailing comma :)
    });

@Eilon
Copy link
Member

Eilon commented Mar 24, 2016

@kichalla please review & merge when you have a chance.

@kichalla
Copy link
Member

In addition, I'm adding duration to the finish events so that consumers only have to subscribe to finish events in order to determine what the duration for a given piece of middleware is.

If users subscribe only to the finish event, then the startTimestamp would be zero causing the duration to be incorrect. Should we always capture startTimestamp then? (but yeah i see you mention about primary execution path)

@dnfclas
Copy link

dnfclas commented Mar 24, 2016

Hi @avanderhoorn, I'm your friendly neighborhood .NET Foundation Pull Request Bot (You can call me DNFBOT). Thanks for your contribution!
You've already signed the contribution license agreement. Thanks!

The agreement was validated by .NET Foundation and real humans are currently evaluating your PR.

TTYL, DNFBOT;

@avanderhoorn
Copy link
Member Author

Whoops didn't meant to close... reopend.

@avanderhoorn
Copy link
Member Author

Ok, I've updated things to fix the line breaks. Additionally, I've updated things so that the startTimestamp is always captured. If we are worried about always capturing that, we can update things to only capture it if either the MiddlewareFinished or MiddlewareException are being listened to, but that check could be more expensive than just capturing the value.

@kichalla
Copy link
Member

:shipit:

@Eilon
Copy link
Member

Eilon commented Mar 24, 2016

Ah yeah I like this fix - I'd like the data to always be accurate, when available.

@kichalla
Copy link
Member

f387d04

@kichalla kichalla closed this Mar 24, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants