[Obsolete("Use Google.Cloud.Diagnostics.AspNetCore.AspNetCoreTraceExtensions instead.")]public static class CloudTraceExtension
Uses the Google Cloud Trace Middleware.
Traces the time taken for all subsequent delegates to run. The time taken
and metadata will be sent to the Google Cloud Trace API. Also allows for more
finely grained manual tracing.
If ExceptionHandling is set to Propagate
and the RequestDelegate executed by this middleware throws ad exception and this
diagnostics library also throws an exception trying to report it and AggregateException
with both exceptions will be thrown. Otherwise only the exception from the RequestDelegate
will be thrown.
UseGoogleTrace(IApplicationBuilder)
[Obsolete("Use Google.Cloud.Diagnostics.AspNetCore.AspNetCoreTraceExtensions.AddGoogleTraceForAspNetCorefor configuring Google Cloud Trace in ASP.NET Core applications. There's no need to explicitly register the middleware.")]public static IApplicationBuilder UseGoogleTrace(this IApplicationBuilder app)
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["\u003cp\u003eThis documentation describes the \u003ccode\u003eCloudTraceExtension\u003c/code\u003e class, which is part of the Google Cloud Diagnostics for ASP.NET Core library, used to trace the time taken for delegates to run and send the data to the Google Cloud Trace API.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eCloudTraceExtension\u003c/code\u003e class and its methods \u003ccode\u003eAddGoogleTrace\u003c/code\u003e and \u003ccode\u003eUseGoogleTrace\u003c/code\u003e are now obsolete, and developers should instead use the \u003ccode\u003eAspNetCoreTraceExtensions\u003c/code\u003e class and its corresponding methods.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eAddGoogleTrace\u003c/code\u003e adds the necessary services for Google Cloud Tracing, requiring an \u003ccode\u003eIServiceCollection\u003c/code\u003e and an action to set up \u003ccode\u003eTraceServiceOptions\u003c/code\u003e, and is used with \u003ccode\u003eUseGoogleTrace\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eUseGoogleTrace\u003c/code\u003e applies middleware to track the duration of all subsequent delegate executions, sending the collected timing and metadata to Google Cloud Trace.\u003c/p\u003e\n"],["\u003cp\u003eIf an exception is thrown by the RequestDelegate and there is also an exception thrown by the diagnostic library when trying to report it and ExceptionHandling is set to Propagate, then an AggregateException with both exceptions will be thrown.\u003c/p\u003e\n"]]],[],null,["# Class CloudTraceExtension (4.4.0)\n\nVersion latestkeyboard_arrow_down\n\n- [4.4.0 (latest)](/dotnet/docs/reference/Google.Cloud.Diagnostics.AspNetCore/latest/Google.Cloud.Diagnostics.AspNetCore.CloudTraceExtension)\n- [4.3.1](/dotnet/docs/reference/Google.Cloud.Diagnostics.AspNetCore/4.3.1/Google.Cloud.Diagnostics.AspNetCore.CloudTraceExtension) \n\n [Obsolete(\"Use Google.Cloud.Diagnostics.AspNetCore.AspNetCoreTraceExtensions instead.\")]\n public static class CloudTraceExtension\n\nUses the Google Cloud Trace Middleware.\nTraces the time taken for all subsequent delegates to run. The time taken\nand metadata will be sent to the Google Cloud Trace API. Also allows for more\nfinely grained manual tracing. \n\nInheritance\n-----------\n\n[Object](https://learn.microsoft.com/dotnet/api/system.object) \\\u003e CloudTraceExtension \n\nInherited Members\n-----------------\n\n[Object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode#system-object-gethashcode) \n[Object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype#system-object-gettype) \n[Object.MemberwiseClone()](https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone#system-object-memberwiseclone) \n[Object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring#system-object-tostring)\n\nNamespace\n---------\n\n[Google.Cloud.Diagnostics.AspNetCore](/dotnet/docs/reference/Google.Cloud.Diagnostics.AspNetCore/latest/Google.Cloud.Diagnostics.AspNetCore)\n\nAssembly\n--------\n\nGoogle.Cloud.Diagnostics.AspNetCore.dll\n\nRemarks\n-------\n\nTraces requests and reports them to Google Cloud Trace.\nDocs: \u003chttps://cloud.google.com/trace/docs/\u003e\n\nMethods\n-------\n\n### AddGoogleTrace(IServiceCollection, Action\\\u003cTraceServiceOptions\\\u003e)\n\n [Obsolete(\"Use Google.Cloud.Diagnostics.AspNetCore.AspNetCoreTraceExtensions.AddGoogleTraceForAspNetCore instead.\")]\n public static IServiceCollection AddGoogleTrace(this IServiceCollection services, Action\u003cTraceServiceOptions\u003e setupAction)\n\nAdds the needed services for Google Cloud Tracing. Used with [UseGoogleTrace(IApplicationBuilder)](/dotnet/docs/reference/Google.Cloud.Diagnostics.AspNetCore/latest/Google.Cloud.Diagnostics.AspNetCore.CloudTraceExtension#Google_Cloud_Diagnostics_AspNetCore_CloudTraceExtension_UseGoogleTrace_Microsoft_AspNetCore_Builder_IApplicationBuilder_).\n\n**Remarks** \nIf [ExceptionHandling](https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.RetryOptions.html#Google_Cloud_Diagnostics_Common_RetryOptions_ExceptionHandling) is set to [Propagate](https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.ExceptionHandling.html#Google_Cloud_Diagnostics_Common_ExceptionHandling_Propagate)\nand the [RequestDelegate](https://learn.microsoft.com/dotnet/api/microsoft.aspnetcore.http.requestdelegate) executed by this middleware throws ad exception and this\ndiagnostics library also throws an exception trying to report it and [AggregateException](https://learn.microsoft.com/dotnet/api/system.aggregateexception)\nwith both exceptions will be thrown. Otherwise only the exception from the [RequestDelegate](https://learn.microsoft.com/dotnet/api/microsoft.aspnetcore.http.requestdelegate)\nwill be thrown.\n\n### UseGoogleTrace(IApplicationBuilder)\n\n [Obsolete(\"Use Google.Cloud.Diagnostics.AspNetCore.AspNetCoreTraceExtensions.AddGoogleTraceForAspNetCorefor configuring Google Cloud Trace in ASP.NET Core applications. There's no need to explicitly register the middleware.\")]\n public static IApplicationBuilder UseGoogleTrace(this IApplicationBuilder app)\n\nUses middleware that will trace time taken for all subsequent delegates to run.\nThe time taken and metadata will be sent to the Google Cloud Trace API. To be\nused with [AddGoogleTrace(IServiceCollection, Action\\\u003cTraceServiceOptions\\\u003e)](/dotnet/docs/reference/Google.Cloud.Diagnostics.AspNetCore/latest/Google.Cloud.Diagnostics.AspNetCore.CloudTraceExtension#Google_Cloud_Diagnostics_AspNetCore_CloudTraceExtension_AddGoogleTrace_Microsoft_Extensions_DependencyInjection_IServiceCollection_System_Action_Google_Cloud_Diagnostics_AspNetCore_TraceServiceOptions__),"]]