# Class CloudTraceExtension (4.4.0)

<button class="button button-with-icon cloud-select-dropdown__button " aria-haspopup="true">Version latest</button>

- [4.4.0 (latest)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.AspNetCore/latest/Google.Cloud.Diagnostics.AspNetCore.CloudTraceExtension)
- [4.3.1](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.AspNetCore/4.3.1/Google.Cloud.Diagnostics.AspNetCore.CloudTraceExtension)

    [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.

## Inheritance

[Object](https://learn.microsoft.com/dotnet/api/system.object) \> CloudTraceExtension

## Inherited Members

[Object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode#system-object-gethashcode) [Object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype#system-object-gettype) [Object.MemberwiseClone()](https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone#system-object-memberwiseclone) [Object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring#system-object-tostring)

## Namespace

[Google.Cloud.Diagnostics.AspNetCore](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.AspNetCore/latest/Google.Cloud.Diagnostics.AspNetCore)

## Assembly

Google.Cloud.Diagnostics.AspNetCore.dll

## Remarks

Traces requests and reports them to Google Cloud Trace.
Docs: <https://cloud.google.com/trace/docs/>

## Methods

### AddGoogleTrace(IServiceCollection, Action\<TraceServiceOptions\>)

    [Obsolete("Use Google.Cloud.Diagnostics.AspNetCore.AspNetCoreTraceExtensions.AddGoogleTraceForAspNetCore instead.")]
    public static IServiceCollection AddGoogleTrace(this IServiceCollection services, Action<TraceServiceOptions> setupAction)

Adds the needed services for Google Cloud Tracing. Used with [UseGoogleTrace(IApplicationBuilder)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.AspNetCore/latest/Google.Cloud.Diagnostics.AspNetCore.CloudTraceExtension#Google_Cloud_Diagnostics_AspNetCore_CloudTraceExtension_UseGoogleTrace_Microsoft_AspNetCore_Builder_IApplicationBuilder_).

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `services` | `https://learn.microsoft.com/dotnet/api/microsoft.extensions.dependencyinjection.iservicecollection` The service collection. Must not be null. |
| `setupAction` | `https://learn.microsoft.com/dotnet/api/system.action-1<https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.AspNetCore/latest/Google.Cloud.Diagnostics.AspNetCore.TraceServiceOptions>` Action to set up options. Must not be null. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/microsoft.extensions.dependencyinjection.iservicecollection` |   |

**Remarks** If [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)
and the [RequestDelegate](https://learn.microsoft.com/dotnet/api/microsoft.aspnetcore.http.requestdelegate) executed by this middleware throws ad exception and this
diagnostics library also throws an exception trying to report it and [AggregateException](https://learn.microsoft.com/dotnet/api/system.aggregateexception)
with both exceptions will be thrown. Otherwise only the exception from the [RequestDelegate](https://learn.microsoft.com/dotnet/api/microsoft.aspnetcore.http.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)

Uses middleware that will trace time taken for all subsequent delegates to run.
The time taken and metadata will be sent to the Google Cloud Trace API. To be
used with [AddGoogleTrace(IServiceCollection, Action\<TraceServiceOptions\>)](https://docs.cloud.google.com/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__),

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `app` | `https://learn.microsoft.com/dotnet/api/microsoft.aspnetcore.builder.iapplicationbuilder` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/microsoft.aspnetcore.builder.iapplicationbuilder` |   |