Skip to content

Commit 9903119

Browse files
CopilotKrzysztofCwalinaheaths
authored
Update README telemetry documentation to use DiagnosticsOptions.IsTelemetryEnabled instead of outdated custom policy approach (Azure#50531)
* Initial plan for issue * Update README telemetry documentation to use DiagnosticsOptions.IsTelemetryEnabled instead of custom policy Co-authored-by: KrzysztofCwalina <[email protected]> * Remove redundant sentence from telemetry documentation Address @heaths feedback to remove the longer, more complex sentence that was redundant with the concise explanation that follows. Co-authored-by: heaths <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: KrzysztofCwalina <[email protected]> Co-authored-by: heaths <[email protected]>
1 parent a9c8174 commit 9903119

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

README.md

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -60,32 +60,23 @@ The software may collect information about you and your use of the software and
6060

6161
Telemetry collection is on by default.
6262

63-
To opt out, you can disable telemetry at client construction. Creating a [synchronous policy](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/Azure.Core/samples/Pipeline.md#implementing-a-synchronous-policy) in your application gives you access to the headers sent with each request, allowing you to remove the `User-Agent` header containing client telemetry. To use the policy, you will add it to the options for your specific client as part of client creation. This will disable Azure SDK telemetry for all methods in the client. You will need to register the policy with each client created.
64-
6563
> NOTE: `HttpClient` may set default user agent headers as part of the .NET platform behavior. This value does not contain any Azure SDK telemetry information.
6664
67-
An example policy implementation looks like:
68-
```C# Snippet:RemoveUserAgentPolicy
69-
public class RemoveUserAgentPolicy : HttpPipelineSynchronousPolicy
70-
{
71-
public override void OnSendingRequest(HttpMessage message)
72-
{
73-
message.Request.Headers.Remove(HttpHeader.Names.UserAgent);
74-
}
75-
}
76-
```
77-
78-
To use it with a client, you would register it to run for every retry attempt as part of your client options:
79-
```C# Snippet:RemoveUserAgentPolicyUse
65+
You can disable telemetry when creating a client by setting the `IsTelemetryEnabled` property in the diagnostics options:
66+
```C#
8067
Uri serviceEndpoint = new Uri("https://example.contoso.com");
8168
TokenCredential credential = new DefaultAzureCredential();
82-
83-
SampleClientOptions clientOptions = new SampleClientOptions();
84-
clientOptions.AddPolicy(new RemoveUserAgentPolicy(), HttpPipelinePosition.PerRetry);
69+
70+
SampleClientOptions clientOptions = new SampleClientOptions()
71+
{
72+
Diagnostics = { IsTelemetryEnabled = false }
73+
};
8574

8675
SampleClient client = new SampleClient(serviceEndpoint, credential, clientOptions);
8776
```
8877

78+
Alternatively, you can disable telemetry globally by setting the `AZURE_TELEMETRY_DISABLED` environment variable to `true` before creating any clients.
79+
8980
### Community
9081

9182
* Chat with other community members [![Join the chat at https://gitter.im/azure/azure-sdk-for-net](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/azure/azure-sdk-for-net?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

0 commit comments

Comments
 (0)