Beobachtbarkeit - AWS Tools for PowerShell

Die vorliegende Übersetzung wurde maschinell erstellt. Im Falle eines Konflikts oder eines Widerspruchs zwischen dieser übersetzten Fassung und der englischen Fassung (einschließlich infolge von Verzögerungen bei der Übersetzung) ist die englische Fassung maßgeblich.

Beobachtbarkeit

Anmerkung

Hierbei handelt es sich um die vorab veröffentlichte Dokumentation für einen Service, dessen Vorversion verfügbar ist. Änderungen sind vorbehalten.

Beobachtbarkeit ist das Ausmaß, in dem der aktuelle Zustand eines Systems aus den ausgegebenen Daten abgeleitet werden kann. Die ausgestrahlten Daten werden allgemein als Telemetrie bezeichnet. Weitere Informationen zur Telemetrie bei der Nutzung von AWS Diensten finden Sie unter Observability im AWS SDK for .NET Developer Guide.

Der folgende Code zeigt ein Beispiel dafür, wie Observability in der aktiviert werden kann. AWS Tools for PowerShell

<# This is an example of generating telemetry for AWS Tools for PowerShell. Each cmdlet that interacts with an Amazon Web Service creates a trace containing spans for underlying processes and AWS SDK for .NET operations. This example is written using PowerShell 7 and .NET 8. It requires the installation of the .NET CLI tool. Note that implementation varies by the exporter/endpoint, which is not specified in this example. For more information, see https://opentelemetry.io/docs/languages/net/exporters/. #> # Set this value to a common folder path on your computer for local development of code repositories. $devProjectsPath = [System.IO.Path]::Join('C:', 'Dev', 'Repos') # If these values are changed, update the hardcoded method invocation toward the end of this script. # Values must follow constraints for namespaces and classes. $telemetryProjectName = 'ExampleAWSPowerShellTelemetryImplementation' $serviceName = 'ExamplePowerShellService' # This example supposes that the OTLP exporter requires these two properties, # but some exporters require different properties or no properties. $telemetryEndPoint = 'https://example-endpoint-provider.io' $telemetryHeaders = 'x-example-header=abc123' $dllsPath = [System.IO.Path]::Join($devProjectsPath, $telemetryProjectName, 'bin', 'Release', 'net8.0', 'publish') $telemetryProjectPath = [System.IO.Path]::Join($devProjectsPath, $telemetryProjectName) # This script is designed to recreate the example telemetry project each time it's executed. Remove-Item -Path $telemetryProjectPath -Recurse -Force -ErrorAction 'SilentlyContinue' $null = New-Item -Path $devProjectsPath -Name $telemetryProjectName -ItemType 'Directory' <# Create and build a C#-based .NET 8 project that implements OpenTelemetry Instrumentation for the AWS Tools for PowerShell. #> Set-Location -Path $telemetryProjectPath dotnet new classlib # Other exporters are available. # For more information, see https://opentelemetry.io/docs/languages/net/exporters/. dotnet add package OpenTelemetry.Exporter.OpenTelemetryProtocol dotnet add package OpenTelemetry.Instrumentation.AWS --prerelease $classContent = @" using OpenTelemetry; using OpenTelemetry.Resources; using OpenTelemetry.Trace; namespace Example.Telemetry; public class AWSToolsForPowerShellTelemetry { public static void InitializeAWSInstrumentation() { Sdk.CreateTracerProviderBuilder() .ConfigureResource(e => e.AddService("$ServiceName")) .AddAWSInstrumentation() // Exporters vary so options might need to be changed or omitted. .AddOtlpExporter(options => { options.Endpoint = new Uri("$telemetryEndPoint"); options.Headers = "$telemetryHeaders"; }) .Build(); } } "@ $csFilePath = [System.IO.Path]::Join($telemetryProjectPath, ($serviceName + '.cs')) Set-Content -Path $csFilePath -Value $classContent dotnet build dotnet publish -c Release <# Add additional modules here for any other cmdlets that you require. Beyond this point, additional AWS Tools for PowerShell modules will fail to import due to conflicts with the AWS SDK for .NET assemblies that are added next. #> Import-Module -Name 'AWS.Tools.Common' Import-Module -Name 'AWS.Tools.DynamoDBv2' # Load assemblies for the telemetry project, excluding the AWS SDK for .NET assemblies # that were already loaded by importing AWS Tools for PowerShell modules. $dlls = (Get-ChildItem $dllsPath -Filter *.dll -Recurse ).FullName $AWSSDKAssembliesAlreadyLoaded = [Threading.Thread]::GetDomain().GetAssemblies().Location | Where-Object {$_ -like '*AWSSDK*' } | Split-Path -Leaf $dlls.Where{$AWSSDKAssembliesAlreadyLoaded -notcontains ($_ | Split-Path -Leaf)}.ForEach{Add-Type -Path $_} # Invoke the method defined earlier in this script. [Example.Telemetry.AWSToolsForPowerShellTelemetry]::InitializeAWSInstrumentation() <# Now telemetry will be exported for AWS Tools for PowerShell cmdlets that are invoked directly or indirectly. Execute this cmdlet or execute your own PowerShell script. #> Get-DDBTable -TableName 'DotNetTests-HashTable' -Region 'us-east-1'