Azure SDK for Rust

repository·main·Indexed 21 days ago

https://github.com/azure/azure-sdk-for-rust

Official collection of crates for interacting with Azure services. Includes documentation for consumers on integration and best practices, as well as developer guides for creating Data and Management Plane clients using TypeSpec, distributed tracing with OpenTelemetry, and internal engineering tools like the MCP server and X509 certificate generation.

Tokens
267.9K
Snippets
492
Records
895
Agent score
73%

What's inside azure-sdk-for-rust

  1. Overview of azure_core

    main

    azure_core is the shared foundation for modern Azure SDK client libraries for Rust. It provides common primitives, abstractions, and helpers to ensure a consistent developer experience across different Azure services.

    Key shared concepts include:

    • Client Configuration: Using ClientOptions to configure retries, logging, and request customization.
    • HTTP Responses: Accessing response details via Response<T>.
    • Paging: Handling asynchronous streams and paging via Pager<T>.
    • Error Handling: Consistent error reporting using azure_core::Error.
    • Authentication: Abstractions for Azure SDK credentials via TokenCredentials.
  2. Overview of Azure Cosmos DB Driver Native C Bindings

    main

    The azure_data_cosmos_driver_native crate provides a C ABI wrapper around the azure_data_cosmos_driver Rust library. It is designed to enable cross-language SDK reuse for languages such as .NET, Java, Go, Python, and native C/C++.

    This crate ships:

    • A cdylib and staticlib named azurecosmosdriver (libazurecosmosdriver.{so,dylib,dll}).
    • A C header file located at include/azurecosmosdriver.h, which is regenerated on every build and is suitable for vendoring in language-binding consumers that do not have a Rust toolchain.
    • A C test harness driven by CMake and Corrosion.
  3. Overview of Azure Canary client library

    main

    The azure_canary crate is a specialized client library designed for two primary purposes:

    1. Azure SDK pipeline testing: It serves as a testing ground for the Azure SDK pipeline.
    2. Rust concept showcase: It is used to demonstrate various Rust themes and concepts, specifically acting as a testing ground for the rust-api-parser.
  4. Azure SDK for Rust – Development Overview

    main
    This documentation collection is intended for contributors building Azure SDK clients, specifically focusing on management plane generation. It provides specialized guides for using TypeSpec to drive client creation and management plane crate generation. For general repository contribution processes, refer to the main repository contribution documentation.
  5. Access Azure SDK for Rust consumer documentation

    main
    The doc/ directory contains documentation specifically intended for developers who want to use the Azure SDKs in their applications. This includes guides on integration, best practices, and specific service usage. For advanced information regarding the internal development of new SDKs, refer to the Development Guides.
  6. How Gateway 2.0 connectivity probing works

    main

    Before any data-plane traffic is sent to a Gateway 2.0 endpoint, the driver performs a lightweight HTTP/2 connectivity probe to ensure TCP, TLS, and HTTP/2 reachability. This prevents opaque RNTBD timeouts caused by firewall or network misconfigurations.

    Probe Wire Contract

    • Method + Path: POST /connectivity-probe
    • Request/Response Body: Empty
    • Protocol: HTTP/2 is required (no HTTP/1.1 fallback)
    • Success (200 OK): Probe enabled, proxy ready.
    • Feature Disabled (503 Service Unavailable): Proxy is reachable, but the enableConnectivityProbe flag is OFF. This is treated as a probe failure.
    • Failure: Any other status, network failure, or timeout indicates the proxy is unreachable.

    Gating Policy

    1. Strict Success: Only a 200 OK response counts as success. A 503 fails the probe, causing the driver to stay on Gateway V1.
    2. All-or-nothing: If the probe fails, Gateway 2.0 is suppressed for every operation and every region across the entire driver. It is not an operation-by-operation downgrade.
    3. Client Opt-out: If gateway_v2_disabled is set to true, the probe is skipped entirely.
  7. Use pre- and post-scripts for resource provisioning

    main

    If your resource provisioning requires extra steps (like generating a certificate), you can use test-resources-pre.ps1 or test-resources-post.ps1 located in the same directory as your test-resources.json file.

    To pass data from a pre-script to the main provisioning script, add entries to the $templateFileParameters hash table. These keys will map directly to the parameters defined in your test-resources.json.

    Example Workflow:

    1. Pre-script: Generates a certificate and adds it to $templateFileParameters.
    2. JSON Template: Defines a parameter (e.g., ConfidentialLedgerPrincipalPEM) that receives the value from the pre-script.
    # Inside test-resources-pre.ps1
    $templateFileParameters['ConfidentialLedgerPrincipalPEM'] = $certValue
    // Inside test-resources.json
    "parameters": {
      "ConfidentialLedgerPrincipalPEM": {
        "type": "string"
      }
    }
  8. Understand HedgeDiagnostics for Cosmos DB hedging

    main

    When using the cross-region hedging strategy, the driver provides HedgeDiagnostics to allow for observability into how the race between the primary and alternate regions was resolved.

    Unlike the .NET SDK, the Rust implementation always attaches the full HedgeDiagnostics whenever a hedging strategy was active (i.e., should_hedge() returned true and execute_hedged() was entered), even if the primary region wins immediately.

    DiagnosticsContext::hedge_diagnostics will be None if:

    • No AvailabilityStrategy was resolved.
    • should_hedge() returned false (e.g., insufficient regions or unsupported ResourceType).
    • The strategy short-circuited before spawning the primary (e.g., due to cancellation).

    To determine if a hedge actually produced the response returned to the caller, do not rely on a boolean; instead, check if the terminal_state is HedgeTerminalState::AlternateWon.

    // Accessing diagnostics from the context
    if let Some(diagnostics) = context.hedge_diagnostics {
        let was_hedge = matches!(diagnostics.terminal_state(), HedgeTerminalState::AlternateWon);
        let winner = diagnostics.response_region();
        // ...
    }
  9. How to use the universal scope parameter

    main

    All Azure.ClientGenerator.Core decorators support an optional scope parameter as their final argument. This allows you to target specific language emitters or exclude them.

    Scope Syntax

    @decoratorName(/* decorator-specific params */, scope?: string)

    Supported Language Identifiers

    • "csharp" - C#/.NET
    • "python" - Python
    • "java" - Java
    • "javascript" - TypeScript/JavaScript
    • "go" - Go
    • "rust" - Rust

    Scope Patterns

    Target Specific Languages

    // Single language
    @@clientName(Foo, "Bar", "python")
    
    // Multiple languages (comma-separated)
    @@clientName(Foo, "Bar", "python, javascript")

    Exclude Languages (Negation)

    Use the ! prefix to exclude languages.

    // All languages EXCEPT C#
    @@clientName(Foo, "Bar", "!csharp")
    
    // All languages EXCEPT python and go
    @@clientName(Foo, "Bar", "!python, !go")
    // Single language
    @@clientName(Foo, "Bar", "python")
    
    // Multiple languages
    @@clientName(Foo, "Bar", "python, javascript")
    
    // Exclude
    @@clientName(Foo, "Bar", "!csharp")