# Google.Cloud.Diagnostics.Common - Class HttpClientBuilderExtensions (5.3.0)

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

- [5.3.0 (latest)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.HttpClientBuilderExtensions)
- [5.2.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/5.2.0/Google.Cloud.Diagnostics.Common.HttpClientBuilderExtensions)
- [5.1.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/5.1.0/Google.Cloud.Diagnostics.Common.HttpClientBuilderExtensions)
- [5.0.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/5.0.0/Google.Cloud.Diagnostics.Common.HttpClientBuilderExtensions)
- [4.4.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/4.4.0/Google.Cloud.Diagnostics.Common.HttpClientBuilderExtensions)
- [4.3.1](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/4.3.1/Google.Cloud.Diagnostics.Common.HttpClientBuilderExtensions)

    public static class HttpClientBuilderExtensions

Reference documentation and code samples for the Google.Cloud.Diagnostics.Common class HttpClientBuilderExtensions.

Extensions methods for [IHttpClientBuilder](https://learn.microsoft.com/dotnet/api/microsoft.extensions.dependencyinjection.ihttpclientbuilder).

## Inheritance

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

## Inherited Members

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

## Namespace

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

## Assembly

Google.Cloud.Diagnostics.Common.dll

## Methods

### AddOutgoingGoogleTraceHandler(IHttpClientBuilder)

    public static IHttpClientBuilder AddOutgoingGoogleTraceHandler(this IHttpClientBuilder clientBuilder)

Adds an [UnchainedTraceHeaderPropagatingHandler](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.UnchainedTraceHeaderPropagatingHandler) to the HTTP client being built,
which will propagate trace information for outgoing requests, made with this client,
when the request being handled by this server is already being traced.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `clientBuilder` | `https://learn.microsoft.com/dotnet/api/microsoft.extensions.dependencyinjection.ihttpclientbuilder` The [IHttpClientBuilder](https://learn.microsoft.com/dotnet/api/microsoft.extensions.dependencyinjection.ihttpclientbuilder) to add this handler to. |

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

### AddOutgoingGoogleTraceHandler(IHttpClientBuilder, Func\<IServiceProvider, IDictionary\<string, string\>\>)

    public static IHttpClientBuilder AddOutgoingGoogleTraceHandler(this IHttpClientBuilder clientBuilder, Func<IServiceProvider, IDictionary<string, string>> labelsProvider)

Adds an [UnchainedTraceHeaderPropagatingHandler](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Diagnostics.Common/latest/Google.Cloud.Diagnostics.Common.UnchainedTraceHeaderPropagatingHandler) to the HTTP client being built,
which will propagate trace information for outgoing requests, made with this client,
when the request being handled by this server is already being traced.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `clientBuilder` | `https://learn.microsoft.com/dotnet/api/microsoft.extensions.dependencyinjection.ihttpclientbuilder` The [IHttpClientBuilder](https://learn.microsoft.com/dotnet/api/microsoft.extensions.dependencyinjection.ihttpclientbuilder) to add this handler to. |
| `labelsProvider` | ``https://learn.microsoft.com/dotnet/api/system.func-2https://learn.microsoft.com/dotnet/api/system.iserviceproviderSystem.Collections.Generic.IDictionary`2https://learn.microsoft.com/dotnet/api/system.stringhttps://learn.microsoft.com/dotnet/api/system.string`` A function that provides labels that will be added to the outgoing trace. The function will be called once per handler, on creation, and the labels obtained at that point will be used for all subsequent requests made through this handler. Note that the scope of the [IServiceProvider](https://learn.microsoft.com/dotnet/api/system.iserviceprovider) argument will share the lifetime of the handler being created. May be null, in which case no costum labels will be added to the outgoing trace. |

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