<!--
Copyright 2025 The Chromium Authors
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->

<!--
This file is used to generate a comprehensive list of Private AI histograms
along with a detailed description for each histogram.

For best practices on writing histogram descriptions, see
https://chromium.googlesource.com/chromium/src.git/+/HEAD/tools/metrics/histograms/README.md

Please follow the instructions in the OWNERS file in this directory to find a
reviewer.
-->

<histogram-configuration>

<histograms>

<!-- LINT.IfChange(PrivateAiFeatures) -->

<variants name="PrivateAiFeatures">
  <variant name="AutomatedPasswordChange"/>
  <variant name="ContextualCueing"/>
  <variant name="DemoGenerateContent"/>
  <variant name="FormsAi"/>
  <variant name="ZeroStateSuggestion"/>
</variants>

<!-- LINT.ThenChange(//components/private_ai/proto/private_ai.proto:FeatureName) -->

<histogram name="PrivateAi.Client.ClientAttestationRequestFailureReason"
    enum="PrivateAiStatusCode" expires_after="2027-01-24">
  <owner>arabm@google.com</owner>
  <owner>dullweber@chromium.org</owner>
  <owner>lamzin@google.com</owner>
  <summary>
    Records the underlying status code (error reason) when the initial client
    attestation request fails. This error is rewritten as
    kClientAttestationFailed on the main request status code metric, and this
    histogram tracks the original failure reason of the request.
  </summary>
</histogram>

<histogram name="PrivateAi.Client.FeatureName" enum="PrivateAiFeatureName"
    expires_after="2027-02-07">
  <owner>nikhiljakhar@google.com</owner>
  <owner>arabm@google.com</owner>
  <owner>dullweber@chromium.org</owner>
  <owner>lamzin@google.com</owner>
  <owner>saeideid@google.com</owner>
  <summary>
    Records the Private AI feature name for each request sent. Recorded for
    every request.
  </summary>
</histogram>

<histogram name="PrivateAi.Client.RequestLatency.{FeatureName}" units="ms"
    expires_after="2027-02-07">
  <owner>arabm@google.com</owner>
  <owner>dullweber@chromium.org</owner>
  <owner>lamzin@google.com</owner>
  <summary>
    Records the latency of a request sent from the Private AI Client. This is
    the time from when the request is sent to when the response is received or
    the request times out. Recorded for every request. The suffix on the
    histogram name indicates the feature: {FeatureName}
  </summary>
  <token key="FeatureName" variants="PrivateAiFeatures"/>
</histogram>

<histogram name="PrivateAi.Client.RequestLatency.{Status}" units="ms"
    expires_after="2027-01-24">
  <owner>nikhiljakhar@google.com</owner>
  <owner>arabm@google.com</owner>
  <owner>dullweber@chromium.org</owner>
  <owner>lamzin@google.com</owner>
  <owner>saeideid@google.com</owner>
  <summary>
    Records the latency of a request sent from the Private AI Client. This is
    the time from when the request is sent to when the response is received or
    the request times out. Recorded for every request. The suffix on the
    histogram name indicates the outcome: {Status}
  </summary>
  <token key="Status">
    <variant name="Error" summary="The request failed with an error."/>
    <variant name="Success" summary="The request was successful."/>
    <variant name="Timeout" summary="The request timed out."/>
  </token>
</histogram>

<histogram name="PrivateAi.Client.RequestSize" units="bytes"
    expires_after="2027-01-24">
  <owner>nikhiljakhar@google.com</owner>
  <owner>arabm@google.com</owner>
  <owner>dullweber@chromium.org</owner>
  <owner>lamzin@google.com</owner>
  <owner>saeideid@google.com</owner>
  <summary>
    Records the size of the request payload sent from the Private AI Client.
    Recorded for every request.
  </summary>
</histogram>

<histogram name="PrivateAi.Client.RequestStatusCode" enum="PrivateAiStatusCode"
    expires_after="2027-01-24">
  <owner>nikhiljakhar@google.com</owner>
  <owner>arabm@google.com</owner>
  <owner>dullweber@chromium.org</owner>
  <owner>lamzin@google.com</owner>
  <owner>saeideid@google.com</owner>
  <summary>
    Records the outcome of a Private AI request. Recorded for every request that
    expects a response.
  </summary>
</histogram>

<histogram name="PrivateAi.Client.RequestStatusCode.{FeatureName}"
    enum="PrivateAiStatusCode" expires_after="2027-01-24">
  <owner>arabm@google.com</owner>
  <owner>dullweber@chromium.org</owner>
  <owner>lamzin@google.com</owner>
  <summary>
    Records the outcome of a Private AI request. Recorded for every request that
    expects a response. Suffix indicates the feature: {FeatureName}
  </summary>
  <token key="FeatureName" variants="PrivateAiFeatures"/>
</histogram>

<histogram name="PrivateAi.Client.ResponseSize.Success" units="bytes"
    expires_after="2027-01-24">
  <owner>nikhiljakhar@google.com</owner>
  <owner>arabm@google.com</owner>
  <owner>dullweber@chromium.org</owner>
  <owner>lamzin@google.com</owner>
  <owner>saeideid@google.com</owner>
  <summary>
    Records the size of the response payload received by the Private AI Client
    for successful requests. Recorded for every successful request.
  </summary>
</histogram>

<histogram name="PrivateAi.Client.ServerStatusCode" enum="GoogleRpcCode"
    expires_after="2027-02-07">
  <owner>nikhiljakhar@google.com</owner>
  <owner>arabm@google.com</owner>
  <owner>dullweber@chromium.org</owner>
  <owner>lamzin@google.com</owner>
  <owner>saeideid@google.com</owner>
  <summary>
    Records the server-side errors that occur during the request lifecycle.
    Recorded for every failed request due to a server error. The error codes are
    based on the canonical Google RPC codes. See
    components/private_ai/proto/google_rpc_code.proto for the enum values.
  </summary>
</histogram>

<histogram name="PrivateAi.Client.WebSocketCloseCode" enum="WebSocketCloseCode"
    expires_after="2027-02-14">
  <owner>nikhiljakhar@google.com</owner>
  <owner>arabm@google.com</owner>
  <owner>dullweber@chromium.org</owner>
  <owner>lamzin@google.com</owner>
  <owner>saeideid@google.com</owner>
  <summary>
    Records the WebSocket close code when the connection is dropped. This helps
    diagnose connection issues. See RFC 6455, Section 7.4.1 for a list of
    defined status codes. Recorded every time the WebSocket channel is dropped.
  </summary>
</histogram>

<histogram name="PrivateAi.Client.WebSocketSessionDuration.ClosedByServer"
    units="ms" expires_after="2027-02-14">
  <owner>nikhiljakhar@google.com</owner>
  <owner>arabm@google.com</owner>
  <owner>dullweber@chromium.org</owner>
  <owner>lamzin@google.com</owner>
  <owner>saeideid@google.com</owner>
  <summary>
    Records the duration of a WebSocket connection starting from when the
    connection is established to when it is closed by the server. Recorded when
    the connection is closed by the server.
  </summary>
</histogram>

<histogram name="PrivateAi.OakSessionSandboxStability.{CallName}"
    enum="BooleanSuccess" expires_after="2026-12-01">
  <owner>nikhiljakhar@google.com</owner>
  <owner>arabm@google.com</owner>
  <owner>dullweber@chromium.org</owner>
  <owner>lamzin@google.com</owner>
  <owner>saeideid@google.com</owner>
  <summary>
    Records the stability of the {CallName} from SecureSessionAsyncImpl to the
    Oak Session service sandbox. True for success, false for failure.
  </summary>
  <token key="CallName">
    <variant name="CompleteHandshake" summary="CompleteHandshake call"/>
    <variant name="Decrypt" summary="Decrypt call"/>
    <variant name="Encrypt" summary="Encrypt call"/>
    <variant name="InitiateHandshake" summary="InitiateHandshake call"/>
  </token>
</histogram>

<histogram name="PrivateAi.Phosphor.ConfigHttp.RequestLatency" units="ms"
    expires_after="2027-01-31">
  <owner>nikhiljakhar@google.com</owner>
  <owner>arabm@google.com</owner>
  <owner>dullweber@chromium.org</owner>
  <owner>lamzin@google.com</owner>
  <owner>saeideid@google.com</owner>
  <summary>
    Records the latency of HTTP requests made by the client to the Phosphor
    server.
  </summary>
</histogram>

<histogram name="PrivateAi.Phosphor.ConfigHttp.ResponseCode"
    enum="HttpResponseCode" expires_after="2027-02-07">
  <owner>nikhiljakhar@google.com</owner>
  <owner>arabm@google.com</owner>
  <owner>dullweber@chromium.org</owner>
  <owner>lamzin@google.com</owner>
  <owner>saeideid@google.com</owner>
  <summary>
    Records the HTTP response code received from Phosphor server. 0 indicates a
    network error or no response.
  </summary>
</histogram>

<histogram name="PrivateAi.Phosphor.FeatureTokenManager.ServedFromCache"
    enum="Boolean" expires_after="2027-02-07">
  <owner>nikhiljakhar@google.com</owner>
  <owner>arabm@google.com</owner>
  <owner>dullweber@chromium.org</owner>
  <owner>lamzin@google.com</owner>
  <owner>saeideid@google.com</owner>
  <summary>
    Records whether a requested auth token was served from the local cache
    (true) or required a fetch (false).
  </summary>
</histogram>

<histogram name="PrivateAi.Phosphor.FeatureTokenManager.TokensFetched"
    units="count" expires_after="2027-02-07">
  <owner>nikhiljakhar@google.com</owner>
  <owner>arabm@google.com</owner>
  <owner>dullweber@chromium.org</owner>
  <owner>lamzin@google.com</owner>
  <owner>saeideid@google.com</owner>
  <summary>
    Records the number of tokens successfully fetched in a batch by
    FeatureTokenManager.
  </summary>
</histogram>

<histogram name="PrivateAi.Phosphor.TokenFetcher.GetAuthnTokens.Result"
    enum="PrivateAiPhosphorGetAuthnTokensResult" expires_after="2027-02-07">
  <owner>nikhiljakhar@google.com</owner>
  <owner>arabm@google.com</owner>
  <owner>dullweber@chromium.org</owner>
  <owner>lamzin@google.com</owner>
  <owner>saeideid@google.com</owner>
  <summary>
    Records the result of the GetAuthnTokens operation in TokenFetcher.
  </summary>
</histogram>

<histogram name="PrivateAi.Phosphor.TokenFetcher.OAuthTokenFetchLatency"
    units="ms" expires_after="2027-01-31">
  <owner>nikhiljakhar@google.com</owner>
  <owner>arabm@google.com</owner>
  <owner>dullweber@chromium.org</owner>
  <owner>lamzin@google.com</owner>
  <owner>saeideid@google.com</owner>
  <summary>
    Records the latency of fetching the OAuth token required for BSA.
  </summary>
</histogram>

<histogram
    name="PrivateAi.SecureChannel.ConnectionEstablishmentLatency.Success"
    units="ms" expires_after="2027-02-07">
  <owner>arabm@google.com</owner>
  <owner>dullweber@chromium.org</owner>
  <owner>lamzin@google.com</owner>
  <summary>
    Records the latency of the whole connection establishment process for the
    secure channel. This measures the duration from when the secure channel
    starts its establishment process to when it is successfully established.
  </summary>
</histogram>

<histogram name="PrivateAi.SecureChannel.GetAttestationRequestLatency.{Status}"
    units="ms" expires_after="2027-01-24">
  <owner>nikhiljakhar@google.com</owner>
  <owner>arabm@google.com</owner>
  <owner>dullweber@chromium.org</owner>
  <owner>lamzin@google.com</owner>
  <owner>saeideid@google.com</owner>
  <summary>
    Records the latency of getting the attestation request. This may involve
    server requests to get a blinded token. The suffix indicates the outcome:
    {Status}.
  </summary>
  <token key="Status">
    <variant name="Error" summary="Getting the attestation request failed."/>
    <variant name="Success"
        summary="Getting the attestation request was successful."/>
  </token>
</histogram>

<histogram name="PrivateAi.SecureChannel.GetHandshakeMessageLatency.{Status}"
    units="ms" expires_after="2027-01-24">
  <owner>nikhiljakhar@google.com</owner>
  <owner>arabm@google.com</owner>
  <owner>dullweber@chromium.org</owner>
  <owner>lamzin@google.com</owner>
  <owner>saeideid@google.com</owner>
  <summary>
    Records the latency of getting the handshake message. The suffix indicates
    the outcome: {Status}.
  </summary>
  <token key="Status">
    <variant name="Error" summary="Getting the handshake message failed."/>
    <variant name="Success"
        summary="Getting the handshake message was successful."/>
  </token>
</histogram>

<histogram name="PrivateAi.SecureChannel.RequestsPerSession" units="requests"
    expires_after="2027-02-07">
  <owner>nikhiljakhar@google.com</owner>
  <owner>arabm@google.com</owner>
  <owner>dullweber@chromium.org</owner>
  <owner>lamzin@google.com</owner>
  <owner>saeideid@google.com</owner>
  <summary>
    Records the number of requests sent in a single secure channel session.
    Recorded when a session is closed.
  </summary>
</histogram>

<histogram
    name="PrivateAi.SecureChannel.SendAttestationRequestLatency.{Status}"
    units="ms" expires_after="2027-01-24">
  <owner>nikhiljakhar@google.com</owner>
  <owner>arabm@google.com</owner>
  <owner>dullweber@chromium.org</owner>
  <owner>lamzin@google.com</owner>
  <owner>saeideid@google.com</owner>
  <summary>
    Records the latency of sending the attestation request and receiving a
    response. This is the time from when the attestation request is sent to when
    the response is received and verified. The suffix indicates the outcome:
    {Status}.
  </summary>
  <token key="Status">
    <variant name="Error"
        summary="The attestation request failed with an error."/>
    <variant name="Success" summary="The attestation was successful."/>
  </token>
</histogram>

<histogram name="PrivateAi.SecureChannel.SendHandshakeRequestLatency.{Status}"
    units="ms" expires_after="2027-01-24">
  <owner>nikhiljakhar@google.com</owner>
  <owner>arabm@google.com</owner>
  <owner>dullweber@chromium.org</owner>
  <owner>lamzin@google.com</owner>
  <owner>saeideid@google.com</owner>
  <summary>
    Records the latency of sending the handshake request and receiving a
    response. This is the time from when the handshake request is sent to when
    the response is received and verified. The suffix indicates the outcome:
    {Status}.
  </summary>
  <token key="Status">
    <variant name="Error"
        summary="The handshake request failed with an error."/>
    <variant name="Success" summary="The handshake was successful."/>
  </token>
</histogram>

<histogram name="PrivateAi.SecureChannel.SessionDuration2" units="ms"
    expires_after="2027-02-07">
  <owner>nikhiljakhar@google.com</owner>
  <owner>arabm@google.com</owner>
  <owner>dullweber@chromium.org</owner>
  <owner>lamzin@google.com</owner>
  <owner>saeideid@google.com</owner>
  <summary>
    Records the duration of a secure channel session. This is the time from when
    the session is established to when it is closed. Recorded when a session is
    closed.
  </summary>
</histogram>

</histograms>

</histogram-configuration>
