Google.Cloud.ErrorReporting.V1Beta1

Google.Cloud.ErrorReporting.V1Beta1 is a.NET client library for theGoogle Cloud Error Reporting API.

Note:This documentation is for version3.0.0-beta06 of the library.Some samples may not work with other versions.

Support for automatic error reporting can be found in theGoogle.Cloud.Diagnostics.AspNetCoreandGoogle.Cloud.Diagnostics.AspNetCore3NuGet packages.

Those packages are generally preferred over using the ErrorReporting API directly.

Installation

Install theGoogle.Cloud.ErrorReporting.V1Beta1 package from NuGet. Add it toyour project in the normal way (for example by right-clicking on theproject in Visual Studio and choosing "Manage NuGet Packages...").Please ensure you enable pre-release packages (for example, in theVisual Studio NuGet user interface, check the "Include prerelease"box). Some of the following samples might only work with the latest pre-release version (3.0.0-beta06) ofGoogle.Cloud.ErrorReporting.V1Beta1.

Authentication

When running on Google Cloud, no action needs to be taken to authenticate.

Otherwise, the simplest way of authenticating your API calls is toset up Application Default Credentials.The credentials will automatically be used to authenticate. SeeSet up Application Default Credentials for more details.

Getting started

All operations are performed through the following client classes:

Create a client instance by calling the staticCreate orCreateAsync methods. Alternatively,use the builder class associated with each client class (e.g. ErrorGroupServiceClientBuilder for ErrorGroupServiceClient)as an easy way of specifying custom credentials, settings, or a custom endpoint. Clients are thread-safe,and we recommend using a single instance across your entire application unless you have a particular needto configure multiple client objects separately.

Using the REST (HTTP/1.1) transport

This library defaults to performing RPCs usinggRPC using the binaryProtocol Buffer wire format.However, it also supports HTTP/1.1 and JSON, for situations where gRPC doesn't work as desired. (This is typically due to an incompatible proxyor other network issue.) To create a client using HTTP/1.1, specify aRestGrpcAdapter reference for theGrpcAdapter property in the client builder.Sample code:

var client = new ErrorGroupServiceClientBuilder{    GrpcAdapter = RestGrpcAdapter.Default}.Build();

For more details, see thetransport selection page.

Sample code using the Error Reporting API directly

Report an error

ReportErrorsServiceClient client = ReportErrorsServiceClient.Create();ProjectName projectName = new ProjectName(projectId);ReportedErrorEvent error = new ReportedErrorEvent{    Context = new ErrorContext    {        ReportLocation = new SourceLocation        {            FilePath = "SampleApp.BusinessLogic/ComplexLogic.cs",            FunctionName = "ComputeTrickyAnswer",            LineNumber = 100        },        User = "userid"    },    // If this is a stack trace, the service will parse it.    Message = "Computation failed",    EventTime = Timestamp.FromDateTime(DateTime.UtcNow),    ServiceContext = new ServiceContext    {        Service = "SampleApp",        Version = "1.0.0"    }};client.ReportErrorEvent(projectName, error);

List error groups with statistics

ErrorStatsServiceClient client = ErrorStatsServiceClient.Create();ProjectName projectName = new ProjectName(projectId);PagedEnumerable<ListGroupStatsResponse, ErrorGroupStats> groupStats = client.ListGroupStats(    projectName,    new QueryTimeRange { Period = Period._30Days });foreach (ErrorGroupStats item in groupStats){    // Sample output: Group: 8002882452986879952; Count: 6; Services: SampleApp/1.0.0    IEnumerable<string> services = item.AffectedServices.Select(s => $"{s.Service}/{s.Version}");    Console.WriteLine($"Group: {item.Group.GroupId}; Count: {item.Count}; Services: {string.Join(", ", services)}");}

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-11-05 UTC.