Table of Contents

Class ServerTimingMetric

Namespace
Cuemon.AspNetCore.Diagnostics
Assembly
Cuemon.AspNetCore.dll

Represents a HTTP Server-Timing header field entry to communicate one metric and description for the given request-response cycle.

public class ServerTimingMetric
Inheritance
ServerTimingMetric

Examples

ServerTimingMetric records performance data points for the HTTP Server-Timing header, supporting metrics with or without duration and description. This example constructs three metrics — "db-query" with 135.2ms duration and a description, "cache-hit" as a marker-only metric, and "redis-get" with a 3.7ms duration — then integrates them with IServerTiming via AddServerTiming to build a complete server-timing collection. Key steps include creating metrics with various constructor overloads and iterating the final list. Console output shows header-value strings such as db-query;dur=135.2;desc="Customer order lookup" and cache-hit.

using System;
using Cuemon.AspNetCore.Diagnostics;

namespace MyApp.Diagnostics
{
    public class ServerTimingMetricExample
    {
        public void Demonstrate()
        {
            // Record a metric for a database query
            var dbMetric = new ServerTimingMetric("db-query",
                TimeSpan.FromMilliseconds(135.2),
                "Customer order lookup");

            Console.WriteLine($"Name: {dbMetric.Name}");
            Console.WriteLine($"Duration: {dbMetric.Duration}ms");
            Console.WriteLine($"Description: {dbMetric.Description}");
            Console.WriteLine($"Header value: {dbMetric}");
            // Output: db-query;dur=135.2;desc="Customer order lookup"

            // Record a metric without duration (marker only)
            var marker = new ServerTimingMetric("cache-hit");
            Console.WriteLine(marker);
            // Output: cache-hit

            // Record a metric without description
            var fastMetric = new ServerTimingMetric("redis-get",
                TimeSpan.FromMilliseconds(3.7));
            Console.WriteLine(fastMetric);
            // Output: redis-get;dur=3.7

            // Use with IServerTiming to add to response
            IServerTiming serverTiming = new ServerTiming();
            serverTiming
                .AddServerTiming("auth", TimeSpan.FromMilliseconds(12.5), "Token validation")
                .AddServerTiming("sql", TimeSpan.FromMilliseconds(89.1), "Product search");

            foreach (var metric in serverTiming.Metrics)
            {
                Console.WriteLine(metric);

}}}
}

Constructors

ServerTimingMetric(string, TimeSpan?, string)

Initializes a new instance of the ServerTimingMetric class.

public ServerTimingMetric(string name, TimeSpan? duration = null, string description = null)

Parameters

name string

The server-specified metric name.

duration TimeSpan?

The server-specified metric duration.

description string

The server-specified metric description.

Properties

Description

Gets the server-specified metric description.

public string Description { get; }

Property Value

string

The server-specified metric description.

Duration

Gets the server-specified metric duration.

public TimeSpan? Duration { get; }

Property Value

TimeSpan?

The server-specified metric duration.

Name

Gets the server-specified metric name.

public string Name { get; }

Property Value

string

The server-specified metric name.

Methods

ToString()

Returns a string that represents this instance.

public override string ToString()

Returns

string

A string that represents this instance.