This directory contains practical examples demonstrating how to use the OpenTelemetry semantic conventions library in Zig applications.
zig build examplesThese examples demonstrate how to use the cloud namespace to describe attributes for virtual machines being monitored across different cloud providers:
aws_ec2.zig- Monitor an AWS EC2 instance with proper cloud attributes including provider, region, availability zone, and resource IDgcp_compute.zig- Monitor a Google Cloud Compute Engine VM with GCP-specific attributesazure_vm.zig- Monitor an Azure Virtual Machine with Azure-specific resource identifiersmulti_cloud.zig- Generic cloud monitoring that works across multiple providers with runtime provider detection
These examples show fundamental usage patterns:
simple_attributes.zig- Basic attribute creation, value setting, and metadata accessattribute_info.zig- Working with attribute metadata like stability levels, requirements, and documentation
const semconv = @import("opentelemetry-semconv");
// Create cloud provider attribute
const provider_attr = semconv.cloud.Registry{ .provider = .{ .value = .aws } };
// Access attribute information
const attr_info = provider_attr.get();const CloudResource = struct {
provider: semconv.cloud.Registry,
region: semconv.cloud.Registry,
account_id: semconv.cloud.Registry,
resource_id: semconv.cloud.Registry,
fn describe(self: CloudResource) void {
// Use attributes for telemetry...
}
};Each cloud provider example shows:
- Correct enum values for that provider
- Typical resource ID formats
- Region and availability zone conventions
- Platform-specific attributes
- Start with
simple_attributes.zigto understand basic usage - Explore
attribute_info.zigto see metadata capabilities - Check provider-specific examples for your cloud environment
- Use
multi_cloud.zigas a template for provider-agnostic monitoring
These examples are designed to be:
- Copy-pasteable into your own projects
- Educational with extensive comments explaining patterns
- Practical showing real-world monitoring scenarios
- Type-safe leveraging Zig's compile-time guarantees
The examples validate that the improved API (using Registry instead of RegistryXXX) provides a clean, intuitive interface for OpenTelemetry semantic conventions in Zig.