Skip to content

Question: How to set the user-agent (and/or X-Goog-Api-Client) header for all requests #226

@tswast

Description

@tswast

Hi, it'd be quite useful for my work to be able to set the user-agent and/or X-Goog-Api-Client as documented in https://cloud.google.com/apis/docs/system-parameters to attribute requests to these libraries and tools built with these libraries.

Per hyperium/tonic#453 (comment) I tried to use an interceptor like this:

    let read_client: GoogleApi<BigQueryReadClient<GoogleAuthMiddleware>> =
        GoogleApi::from_function(
            // Maximum row size in BigQuery is 100 MB, so this should allow for
            // the largest possible row plus some overhead.
            |inner| BigQueryReadClient::with_interceptor(
                inner,  |mut req: tonic::Request<()>| {
                    req.metadata_mut().insert(
                        "user-agent",
                        tonic::metadata::MetadataValue::from_str("some-user-agent").unwrap(),
                    );
                    Ok(req)
                }
            ).max_decoding_message_size(101 * 1024 * 1024),
            "https://bigquerystorage.googleapis.com",
            None,
        )
        .await?;

But I get a type error.

`?` operator has incompatible types
`?` operator cannot convert from `GoogleApiClient<GoogleApiClientBuilderFunction<...>, ...>` to `GoogleApiClient<GoogleApiClientBuilderFunction<...>, ...>`
expected struct `GoogleApiClient<GoogleApiClientBuilderFunction<...>, ...>` (`GoogleAuthMiddlewareService<Channel>`)
   found struct `GoogleApiClient<GoogleApiClientBuilderFunction<...>, ...>` (`InterceptedService<..., ...>`)
the full name for the type has been written to '/usr/local/google/home/swast/src/github.com/pola-rs/polars-bigquery-client/target/debug/deps/polars_bigquery-67ec6568e750e1b9.long-type-13703174448194782730.txt'
consider using `--verbose` to print the full type name to the consolerustc[Click for full compiler diagnostic](rust-analyzer-diagnostics-view:/diagnostic%20message%20[5]?5#file:///usr/local/google/home/swast/src/github.com/pola-rs/polars-bigquery-client/src/bigquery.rs)
`?` operator has incompatible types
`?` operator cannot convert from `GoogleApiClient<GoogleApiClientBuilderFunction<...>, ...>` to `GoogleApiClient<GoogleApiClientBuilderFunction<...>, ...>`
expected struct `GoogleApiClient<GoogleApiClientBuilderFunction<...>, ...>` (`GoogleAuthMiddlewareService<Channel>`)
   found struct `GoogleApiClient<GoogleApiClientBuilderFunction<...>, ...>` (`InterceptedService<..., ...>`)
the full name for the type has been written to '/usr/local/google/home/swast/src/github.com/pola-rs/polars-bigquery-client/target/debug/deps/polars_bigquery-c61b4cad463e858a.long-type-18130587985917432528.txt'
consider using `--verbose` to print the full type name to the consolerustc

In particular,

expected struct `GoogleApiClient<GoogleApiClientBuilderFunction<...>, ...>` (`GoogleAuthMiddlewareService<Channel>`)
   found struct `GoogleApiClient<GoogleApiClientBuilderFunction<...>, ...>` (`InterceptedService<..., ...>`)` 

is coming from from_function.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions