View a markdown version of this page

Use StopOTelEnrichment with an AWS SDK - AWS SDK Code Examples

There are more AWS SDK examples available in the AWS Doc SDK Examples GitHub repo.

Use StopOTelEnrichment with an AWS SDK

The following code examples show how to use StopOTelEnrichment.

Action examples are code excerpts from larger programs and must be run in context. You can see this action in context in the following code example:

.NET
SDK for .NET (v4)
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

/// <summary> /// Turn off OTel enrichment for the account. Existing PromQL alarms are not deleted, /// but vended metrics stop being enriched with resource ARN and tag labels, so /// queries that select on those labels stop matching. /// </summary> /// <returns>True if successful.</returns> public async Task<bool> StopOTelEnrichment() { var response = await _amazonCloudWatch.StopOTelEnrichmentAsync( new StopOTelEnrichmentRequest()); _logger.LogInformation("Stopped OTel enrichment for this account."); return response.HttpStatusCode == System.Net.HttpStatusCode.OK; }
C++
SDK for C++
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

Include the required files.

#include <aws/core/Aws.h> #include <aws/monitoring/CloudWatchClient.h> #include <aws/monitoring/model/StopOTelEnrichmentRequest.h> #include <iostream>

Stop OpenTelemetry enrichment.

Aws::Client::ClientConfiguration clientConfig; // Optional: Set to the AWS Region (overrides config file). // clientConfig.region = "us-east-1"; Aws::CloudWatch::CloudWatchClient cw(clientConfig); Aws::CloudWatch::Model::StopOTelEnrichmentRequest request; auto outcome = cw.StopOTelEnrichment(request); if (!outcome.IsSuccess()) { std::cerr << "Failed to stop OTel enrichment: " << outcome.GetError().GetMessage() << std::endl; } else { std::cout << "Successfully stopped OTel enrichment for this account." << std::endl; }
Java
SDK for Java 2.x
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

/** * Turns off OTel enrichment for the account. Existing PromQL alarms are not * deleted, but vended metrics stop being enriched with resource ARN and tag labels, * so queries that select on those labels stop matching. * * @param cw the CloudWatch client */ public static void stopOTelEnrichment(CloudWatchClient cw) { try { cw.stopOTelEnrichment(StopOTelEnrichmentRequest.builder().build()); System.out.println("Stopped OTel enrichment for this account."); } catch (CloudWatchException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } }
JavaScript
SDK for JavaScript (v3)
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

import { StopOTelEnrichmentCommand } from "@aws-sdk/client-cloudwatch"; import { client } from "../libs/client.js"; // Turn off OTel enrichment for the account. Existing PromQL alarms are not deleted, // but vended metrics stop being enriched with resource ARN and tag labels, so queries // that select on those labels stop matching. const run = async () => { const command = new StopOTelEnrichmentCommand({}); try { return await client.send(command); } catch (err) { console.error(err); } }; export default run();
Kotlin
SDK for Kotlin
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

suspend fun stopOTelEnrichment() { CloudWatchClient.fromEnvironment { region = "us-east-1" }.use { cwClient -> cwClient.stopOTelEnrichment(StopOTelEnrichmentRequest {}) println("Successfully stopped OTel enrichment for this account") } }
Python
SDK for Python (Boto3)
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

class CloudWatchOTelWrapper: """Encapsulates the OpenTelemetry-oriented Amazon CloudWatch operations.""" def __init__(self, cloudwatch_client): """ :param cloudwatch_client: A Boto3 CloudWatch client. The OpenTelemetry operations are only available on the client interface, not on the higher-level ``boto3.resource("cloudwatch")`` interface. """ self.cloudwatch_client = cloudwatch_client @classmethod def from_client(cls): """ Creates a wrapper backed by a default CloudWatch client. :return: A CloudWatchOTelWrapper. """ return cls(boto3.client("cloudwatch")) def stop_otel_enrichment(self): """ Turns off OTel enrichment for the account. Existing PromQL alarms are not deleted, but vended metrics stop being enriched with resource ARN and tag labels, so queries that select on those labels stop matching. """ try: self.cloudwatch_client.stop_o_tel_enrichment() logger.info("Stopped OTel enrichment for this account.") except ClientError: logger.exception("Couldn't stop OTel enrichment.") raise
Ruby
SDK for Ruby
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

# Turns off OTel enrichment for the account. Existing PromQL alarms are not deleted, but # vended metrics stop being enriched with resource ARN and tag labels, so queries that # select on those labels stop matching. # # @param cloudwatch_client [Aws::CloudWatch::Client] An initialized CloudWatch client. # @return [Boolean] true if enrichment was stopped; otherwise, false. def otel_enrichment_stopped?(cloudwatch_client) cloudwatch_client.stop_o_tel_enrichment true rescue StandardError => e puts "Error stopping OTel enrichment: #{e.message}" false end