@@ -23,13 +23,16 @@ const std = @import("std");
2323const semconv = @import("opentelemetry-semconv");
2424
2525pub fn main() !void {
26- // Use Deployment semantic conventions
27- const deploy_attr = semconv.deployment.deployment_environment_name;
28- const deploy_key = deploy_attr.name;
29- const deploy_status = .succeeded;
26+ // Use HTTP semantic conventions
27+ const http_method_attr = semconv.http.Registry.http_request_method;
28+ const method_value = semconv.http.Registry.requestMethodValue.get;
29+
30+ // Use JVM semantic conventions
31+ const jvm_version_attr = semconv.jvm.Registry.jvm_version;
3032
3133 // Here you would actually set the attribute on metrics data point, log/event or trace attributes
32- std.debug.print("Setting event with attribute: {s} = {s}\n", .{deploy_key, deploy_status.toString()});
34+ std.debug.print("HTTP Method: {s} = {s}\n", .{ http_method_attr.base.name, method_value.toString() });
35+ std.debug.print("JVM Version attribute: {s}\n", .{jvm_version_attr.name});
3336}
3437```
3538
@@ -53,10 +56,17 @@ Many semantic conventions include well-known enum values, for example for `http`
5356``` zig
5457const semconv = @import("opentelemetry-semconv");
5558
56- const http_attr = semconv.http.RegistryHttp{ .requestMethod = .get};
57- const attribute_name = if(http_attr.get().stability == .stable){
58- http_attr.get().name;
59- } else "custom.http.request.attribute.key"
59+ // Access HTTP request method attribute and enum values
60+ const http_method_attr = semconv.http.Registry.http_request_method;
61+ const get_method = semconv.http.Registry.requestMethodValue.get;
62+
63+ // Check stability and use the attribute
64+ const attribute_name = if (http_method_attr.base.stability == .stable)
65+ http_method_attr.base.name
66+ else
67+ "custom.http.request.method";
68+
69+ std.debug.print("Attribute: {s}, Method: {s}\n", .{ attribute_name, get_method.toString() });
6070```
6171
6272You can use stability levels to discern if an attribute should be in place.
@@ -94,19 +104,24 @@ The library is organized as follows:
94104The library uses a hierarchical type system:
95105
96106``` zig
97- // Base attribute type (generic)
98- Attribute(ValueType)
99-
100- // Specialized attribute types
101- StringAttribute = Attribute([]const u8)
102- IntAttribute = Attribute(i64)
103- BoolAttribute = Attribute(bool)
107+ // Base attribute types
108+ StringAttribute = struct {
109+ name: []const u8,
110+ brief: []const u8,
111+ note: ?[]const u8,
112+ stability: StabilityLevel,
113+ requirement_level: RequirementLevel,
114+ }
104115
105116// Enum attributes with well-known values
106117EnumAttribute(EnumType) = struct {
107118 base: StringAttribute,
108- well_known_values: []const EnumType,
119+ well_known_values: EnumType,
109120}
121+
122+ // Accessing attributes
123+ const http_method = semconv.http.Registry.http_request_method; // EnumAttribute
124+ const http_body_size = semconv.http.Registry.http_request_body_size; // StringAttribute
110125```
111126
112127## Testing
0 commit comments