From 5c959d39d4ad98ae75fc19feca9b04540c9f4079 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laurent=20Qu=C3=A9rel?= Date: Sat, 4 May 2024 08:22:13 -0700 Subject: [PATCH] Delete templates directory containing tera templates --- templates/go/config.yaml | 15 - templates/go/optional_attrs.macro.tera | 52 -- templates/go/otel/attribute/attrs.go.tera | 15 - templates/go/otel/client.go.tera | 181 ------- templates/go/otel/eventer/event.tera | 57 --- templates/go/otel/meter/metric.tera | 462 ------------------ templates/go/otel/meter/metric_group.tera | 20 - templates/go/otel/tracer/span.tera | 160 ------ templates/go/required_attrs.macro.tera | 54 -- .../registry/markdown/attribute_group.md | 46 -- .../registry/markdown/attribute_groups.md | 47 -- templates/registry/markdown/attribute_type.j2 | 5 - templates/registry/markdown/event.md | 47 -- templates/registry/markdown/events.md | 48 -- templates/registry/markdown/examples.j2 | 7 - templates/registry/markdown/group.md | 56 --- templates/registry/markdown/groups.md | 56 --- .../registry/markdown/groups_per_prefix.md | 50 -- templates/registry/markdown/metric.md | 52 -- templates/registry/markdown/metrics.md | 53 -- templates/registry/markdown/registry.md | 52 -- templates/registry/markdown/resource.md | 46 -- templates/registry/markdown/resources.md | 47 -- templates/registry/markdown/scope.md | 0 templates/registry/markdown/span.md | 49 -- templates/registry/markdown/spans.md | 50 -- templates/registry/markdown/weaver.yaml | 43 -- templates/rust/config.yaml | 15 - templates/rust/eventer/mod.rs.tera | 19 - templates/rust/meter/mod.rs.tera | 94 ---- templates/rust/mod.rs.tera | 7 - templates/rust/span.tera.bak | 142 ------ templates/rust/tracer/mod.rs.tera | 142 ------ 33 files changed, 2189 deletions(-) delete mode 100644 templates/go/config.yaml delete mode 100644 templates/go/optional_attrs.macro.tera delete mode 100644 templates/go/otel/attribute/attrs.go.tera delete mode 100644 templates/go/otel/client.go.tera delete mode 100644 templates/go/otel/eventer/event.tera delete mode 100644 templates/go/otel/meter/metric.tera delete mode 100644 templates/go/otel/meter/metric_group.tera delete mode 100644 templates/go/otel/tracer/span.tera delete mode 100644 templates/go/required_attrs.macro.tera delete mode 100644 templates/registry/markdown/attribute_group.md delete mode 100644 templates/registry/markdown/attribute_groups.md delete mode 100644 templates/registry/markdown/attribute_type.j2 delete mode 100644 templates/registry/markdown/event.md delete mode 100644 templates/registry/markdown/events.md delete mode 100644 templates/registry/markdown/examples.j2 delete mode 100644 templates/registry/markdown/group.md delete mode 100644 templates/registry/markdown/groups.md delete mode 100644 templates/registry/markdown/groups_per_prefix.md delete mode 100644 templates/registry/markdown/metric.md delete mode 100644 templates/registry/markdown/metrics.md delete mode 100644 templates/registry/markdown/registry.md delete mode 100644 templates/registry/markdown/resource.md delete mode 100644 templates/registry/markdown/resources.md delete mode 100644 templates/registry/markdown/scope.md delete mode 100644 templates/registry/markdown/span.md delete mode 100644 templates/registry/markdown/spans.md delete mode 100644 templates/registry/markdown/weaver.yaml delete mode 100644 templates/rust/config.yaml delete mode 100644 templates/rust/eventer/mod.rs.tera delete mode 100644 templates/rust/meter/mod.rs.tera delete mode 100644 templates/rust/mod.rs.tera delete mode 100644 templates/rust/span.tera.bak delete mode 100644 templates/rust/tracer/mod.rs.tera diff --git a/templates/go/config.yaml b/templates/go/config.yaml deleted file mode 100644 index 452e1bf4..00000000 --- a/templates/go/config.yaml +++ /dev/null @@ -1,15 +0,0 @@ -file_name: snake_case -function_name: PascalCase -arg_name: camelCase -struct_name: PascalCase -field_name: PascalCase - -type_mapping: - int: int64 - double: double - boolean: bool - string: string - "int[]": "[]int64" - "double[]": "[]double" - "boolean[]": "[]bool" - "string[]": "[]string" \ No newline at end of file diff --git a/templates/go/optional_attrs.macro.tera b/templates/go/optional_attrs.macro.tera deleted file mode 100644 index 89fcf653..00000000 --- a/templates/go/optional_attrs.macro.tera +++ /dev/null @@ -1,52 +0,0 @@ -{% macro attr_type(prefix) -%}Optional{{prefix}}Attribute{% endmacro attr_type %} - -{% macro declare_attrs(prefix="", marker, attrs) -%} -{% set not_require_attrs = attrs | not_required | without_value %} -{%- if not_require_attrs | length > 0 -%} -// =============================================== -// ====== Definition of optional attributes ====== -// =============================================== - -// Optional{{marker}}Attribute is an interface implemented by all optional attributes of the {{marker}}. -type Optional{{marker}}Attribute interface { - Attribute() otel_attr.KeyValue - {{ marker | function_name }}Marker() -} - -{% for attr in not_require_attrs | without_enum %} -// {{prefix}}{{attr.id | struct_name}}OptAttr represents an optional attribute. -// {{ [attr.brief, attr.note, "", "# Examples", attr.examples] | comment(prefix="// ") }} -func {{prefix}}{{attr.id | struct_name}}OptAttr(v {{ attr.type | type_mapping(enum=attr.id | struct_name) }}) {{prefix}}{{attr.id | struct_name}}OptAttrWrapper { return {{prefix}}{{attr.id | struct_name}}OptAttrWrapper{v} } -// {{prefix}}{{attr.id | struct_name}}OptAttrWrapper is a wrapper for the attribute `{{attr.id}}`. -// Use the function {{attr.id | struct_name}}OptAttr(value) to create an instance. -type {{prefix}}{{attr.id | struct_name}}OptAttrWrapper struct { {{ attr.type | type_mapping(enum=attr.id | struct_name) }} } -func (w {{prefix}}{{attr.id | struct_name}}OptAttrWrapper) Attribute() otel_attr.KeyValue { - return attribute.{{ attr.id | field_name }}Key.{{ attr.type | type_mapping(enum="String" | struct_name) | function_name }}(w.{{ attr.type | type_mapping(enum="string" | struct_name) }}) -} -func (w {{prefix}}{{attr.id | struct_name}}OptAttrWrapper) {{marker}}Marker() {} - -{% endfor %} - -{% for attr in not_require_attrs | with_enum %} -// {{prefix}}{{attr.id | struct_name}}OptAttr represents an optional attribute. -// {{ [attr.brief, attr.note, "", "# Examples", attr.examples] | comment(prefix="// ") }} -func {{prefix}}{{attr.id | struct_name}}OptAttr(v {{ attr.type | type_mapping(enum=attr.id | struct_name) }}) {{prefix}}{{attr.id | struct_name}}OptAttrWrapper { return {{prefix}}{{attr.id | struct_name}}OptAttrWrapper{v} } -// {{prefix}}{{attr.id | struct_name}}OptAttrWrapper is a wrapper for the attribute `{{attr.id}}`. -// Use the function {{attr.id | struct_name}}OptAttr(value) to create an instance. -type {{prefix}}{{attr.id | struct_name}}OptAttrWrapper struct { {{ attr.type | type_mapping(enum=attr.id | struct_name) }} } -func (w {{prefix}}{{attr.id | struct_name}}OptAttrWrapper) Attribute() otel_attr.KeyValue { - return attribute.{{ attr.id | field_name }}Key.String(string(w.{{ attr.type | type_mapping(enum=attr.id | struct_name) }})) -} -func (w {{prefix}}{{attr.id | struct_name}}OptAttrWrapper) {{marker}}Marker() {} - -type {{attr.id | struct_name}} string -const ( -{% for variant in attr.type.members %} - // {{variant.id | struct_name}} is a possible value of {{attr.id | struct_name}}. - // {{ [variant.brief, variant.note] | comment(prefix=" // ") }} - {{variant.id | struct_name}} {{attr.id | struct_name}} = "{{variant.id}}" -{%- endfor %} -) -{% endfor %} -{%- endif -%} -{% endmacro declare_attrs %} \ No newline at end of file diff --git a/templates/go/otel/attribute/attrs.go.tera b/templates/go/otel/attribute/attrs.go.tera deleted file mode 100644 index ec1fd2f3..00000000 --- a/templates/go/otel/attribute/attrs.go.tera +++ /dev/null @@ -1,15 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 - -package attribute - -import ( - "go.opentelemetry.io/otel/attribute" -) - -{% set attrs = schema | unique_attributes(recursive=true) -%} -// Declaration of all attribute keys. -var ( -{%- for attr in attrs %} - {{ attr.id | field_name }}Key = attribute.Key("{{attr.id}}") -{%- endfor %} -) \ No newline at end of file diff --git a/templates/go/otel/client.go.tera b/templates/go/otel/client.go.tera deleted file mode 100644 index 7ec1ba53..00000000 --- a/templates/go/otel/client.go.tera +++ /dev/null @@ -1,181 +0,0 @@ -{% import "required_attrs.macro.tera" as required %} -{% import "optional_attrs.macro.tera" as optional %} -package otel - -import ( - "context" - "fmt" - "log" - "os" - "time" - - "go.opentelemetry.io/otel" - otel_attr "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/exporters/stdout/stdoutmetric" - "go.opentelemetry.io/otel/exporters/stdout/stdouttrace" - "go.opentelemetry.io/otel/metric" - sdkmetric "go.opentelemetry.io/otel/sdk/metric" - "go.opentelemetry.io/otel/sdk/resource" - sdktrace "go.opentelemetry.io/otel/sdk/trace" - "go.opentelemetry.io/otel/trace" - - "go_test/pkg/otel/attribute" -) - -const ( - InstrumentationName = "{{ schema.instrumentation_library.name }}" - InstrumentationVersion = "{{ schema.instrumentation_library.version }}" -) - -var ( - Meter = otel.GetMeterProvider().Meter( - InstrumentationName, - metric.WithInstrumentationVersion(InstrumentationVersion), - metric.WithSchemaURL("{{ schema_url }}"), - ) - Tracer = otel.GetTracerProvider().Tracer( - InstrumentationName, - trace.WithInstrumentationVersion(InstrumentationVersion), - trace.WithSchemaURL("{{ schema_url }}"), - ) -) - -// ClientHandler is a handler for the OTel Weaver client. -type ClientHandler struct { - ctx context.Context - metricShutdown func(context.Context) error - traceShutdown func(context.Context) error -} - -{%- set required_attrs = schema.resource.attributes | required | without_value -%} -{%- set not_required_attrs = schema.resource.attributes | not_required | without_value %} - -{{ required::declare_attrs(attrs=required_attrs) }} -{{ optional::declare_attrs(marker="Resource", attrs=not_required_attrs) }} - -// ================== -// ===== Client ===== -// ================== - -// Client returns a OTel client (generated by OTel Weaver). -// It uses a context initialized with `context.Background()`. -func Client( - {{- required::declare_args(attrs=required_attrs) }} - {% if not_required_attrs | length > 0 -%}optionalAttributes ...OptionalResourceAttribute,{% endif %} -) *ClientHandler { - return ClientWithContext( - context.Background(), - {%- for attr in required_attrs %} - {{attr.id | arg_name}}, - {%- endfor %} - {% if not_required_attrs | length > 0 -%}optionalAttributes...,{% endif %} - ) -} - -// ClientWithContext returns a OTel client with a given context (generated by OTel Weaver). -func ClientWithContext( - ctx context.Context, - {{- required::declare_args(attrs=required_attrs) }} - {% if not_required_attrs | length > 0 -%}optionalAttributes ...OptionalResourceAttribute,{% endif %} -) *ClientHandler { - metricShutdown, traceShutdown, err := installExportPipeline( - {%- for attr in required_attrs %} - {{attr.id | arg_name}}, - {%- endfor %} - {% if not_required_attrs | length > 0 -%}optionalAttributes...,{% endif %} - ) - if err != nil { - log.Fatal(err) - } - - return &ClientHandler{ - ctx: ctx, - metricShutdown: metricShutdown, - traceShutdown: traceShutdown, - } -} - -func (o *ClientHandler) Shutdown() { - metricErr := o.metricShutdown(o.ctx) - traceErr := o.traceShutdown(o.ctx) - - mustExit := false - if metricErr != nil { - log.Println(metricErr) - mustExit = true - } - if traceErr != nil { - log.Println(traceErr) - mustExit = true - } - if mustExit { - os.Exit(1) - } -} - -func resourceBuilder( - {%- for attr in required_attrs %} - {{attr.id | arg_name}} {{attr.id | struct_name}}ReqAttrWrapper, - {%- endfor %} - {% if not_required_attrs | length > 0 -%}optionalAttributes ...OptionalResourceAttribute,{% endif %} -) *resource.Resource { - attrs := []otel_attr.KeyValue { - {%- for attr in schema.resource.attributes | with_value %} - attribute.{{ attr.id | field_name }}Key.{{ attr.type | type_mapping(enum=attr.id | struct_name) | function_name }}({{ attr.value | value }}), - {%- endfor %} - {%- for attr in required_attrs %} - {{attr.id | arg_name}}.Attribute(), - {%- endfor %} - } - {% if not_required_attrs | length > 0 -%} - for _, attr := range optionalAttributes { - attrs = append(attrs, attr.Attribute()) - } - {% endif %} - return resource.NewWithAttributes("{{ schema_url }}", attrs...) -} - -func installExportPipeline( - {%- for attr in required_attrs %} - {{attr.id | arg_name}} {{attr.id | struct_name}}ReqAttrWrapper, - {%- endfor %} - {% if not_required_attrs | length > 0 -%}optionalAttributes ...OptionalResourceAttribute,{% endif %} -) (metricShutdown func(context.Context) error, traceShutdown func(context.Context) error, err error) { - metricExporter, err := stdoutmetric.New(stdoutmetric.WithPrettyPrint()) - if err != nil { - err = fmt.Errorf("creating metric stdout exporter: %w", err) - return - } - - traceExporter, err := stdouttrace.New(stdouttrace.WithPrettyPrint()) - if err != nil { - err = fmt.Errorf("creating trace stdout exporter: %w", err) - return - } - - metricProvider := sdkmetric.NewMeterProvider( - sdkmetric.WithReader(sdkmetric.NewPeriodicReader(metricExporter, sdkmetric.WithInterval(3*time.Second))), - sdkmetric.WithResource(resourceBuilder( - {%- for attr in required_attrs %} - {{attr.id | arg_name}}, - {%- endfor %} - {% if not_required_attrs | length > 0 -%}optionalAttributes...,{% endif %} - )), - ) - otel.SetMeterProvider(metricProvider) - - tracerProvider := sdktrace.NewTracerProvider( - sdktrace.WithBatcher(traceExporter), - sdktrace.WithResource(resourceBuilder( - {%- for attr in required_attrs %} - {{attr.id | arg_name}}, - {%- endfor %} - {% if not_required_attrs | length > 0 -%}optionalAttributes...,{% endif %} - )), - ) - otel.SetTracerProvider(tracerProvider) - - metricShutdown = metricProvider.Shutdown - traceShutdown = tracerProvider.Shutdown - return -} \ No newline at end of file diff --git a/templates/go/otel/eventer/event.tera b/templates/go/otel/eventer/event.tera deleted file mode 100644 index 5e489334..00000000 --- a/templates/go/otel/eventer/event.tera +++ /dev/null @@ -1,57 +0,0 @@ -{% import "required_attrs.macro.tera" as required %} -{% import "optional_attrs.macro.tera" as optional %} -{# Define the file name for the generated code #} -{%- set file_name = event_name | file_name -%} -{{- config(file_name="otel/eventer/event_" ~ file_name ~ "/event.go") -}} -// SPDX-License-Identifier: Apache-2.0 - -package {{ event_name | file_name }} - -import ( - "context" - - otel_attr "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/trace" - - client "go_test/pkg/otel" - "go_test/pkg/otel/attribute" -) - -// Event records a new `{{ event_name }}` event with -// the given required attributes. -func Event( - {{- required::declare_args(attrs=attributes) }} - optionalAttributes ...{{ optional::attr_type(prefix="Span") }}, -) { - EventWithContext( - context.TODO(), - {%- for attr in attributes | required | without_value %} - {{attr.id | arg_name}}, - {%- endfor %} - optionalAttributes..., - ) -} - -// EventWithContext records a new `{{ event_name }}` event with -// the given context and required attributes. -func EventWithContext( - ctx context.Context, - {{- required::declare_args(attrs=attributes) }} - optionalAttributes ...{{ optional::attr_type(prefix="Span") }}, -) { - - ctx, span := client.Tracer.Start(ctx, "{{ event_name }}", - {%- for attr in attributes | with_value %} - trace.WithAttributes(attribute.{{ attr.id | function_name }}Key.{{attr.type | type_mapping(enum=attr.id) | function_name}}({{attr.value | value}})), - {%- endfor %} - {%- for attr in attributes | required | without_value %} - trace.WithAttributes({{ attr.id | arg_name }}.Attribute()), - {%- endfor %} - ) - for _, opt := range optionalAttributes { - span.SetAttributes(opt.Attribute()) - } -} - -{{ required::declare_attrs(attrs=attributes) }} -{{ optional::declare_attrs(marker="Span", attrs=attributes) }} diff --git a/templates/go/otel/meter/metric.tera b/templates/go/otel/meter/metric.tera deleted file mode 100644 index 4e2a5cc7..00000000 --- a/templates/go/otel/meter/metric.tera +++ /dev/null @@ -1,462 +0,0 @@ -{% import "required_attrs.macro.tera" as required %} -{% import "optional_attrs.macro.tera" as optional %} -{# Define the file name for the generated code #} -{%- set file_name = name | file_name -%} -{{- config(file_name="otel/meter/metric_" ~ file_name ~ "/metric.go") -}} -// SPDX-License-Identifier: Apache-2.0 - -package {{ name | file_name }} - -import ( - "context" - - otel_attr "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/metric" - - client "go_test/pkg/otel" - "go_test/pkg/otel/attribute" -) - -type Int64Observer func() (int64, {% for attr in attributes | required | without_value %}{{attr.id | struct_name}}ReqAttrWrapper, {% endfor %}[]OptionalMetricAttribute, error) -type Float64Observer func() (float64, {% for attr in attributes | required | without_value %}{{attr.id | struct_name}}ReqAttrWrapper, {% endfor %}[]OptionalMetricAttribute, error) - -{% if instrument == "counter" %} -// ===== Synchronous Counter Declaration ===== -type Int64Counter_ struct { - ctx context.Context - counter metric.Int64Counter -} - -type Float64Counter_ struct { - ctx context.Context - counter metric.Float64Counter -} - -func Int64Counter() (*Int64Counter_, error) { - return Int64CounterWithContext(context.TODO()) -} - -func Int64CounterWithContext(ctx context.Context) (*Int64Counter_, error) { - counter, err := client.Meter.Int64Counter( - "{{name}}", - metric.WithDescription("{{brief}}"), - metric.WithUnit("{{unit}}"), - ) - if err != nil { - return nil, err - } - return &Int64Counter_{ - ctx: ctx, - counter: counter, - }, nil -} - -func (g *Int64Counter_) Add(incr uint64, {% for attr in attributes | required | without_value %}{{attr.id | arg_name}} {{attr.id | struct_name}}ReqAttrWrapper, {% endfor %}optAttrs ...OptionalMetricAttribute) { - options := []metric.AddOption { - {% for attr in attributes | required | without_value %}metric.WithAttributes({{attr.id | arg_name}}.Attribute()),{% endfor %} - } - for _, opt := range optAttrs { - options = append(options, metric.WithAttributes(opt.Attribute())) - } - g.counter.Add(g.ctx, int64(incr), options...) -} - -func (g *Int64Counter_) AddWithContext(ctx context.Context, incr uint64, {% for attr in attributes | required | without_value %}{{attr.id | arg_name}} {{attr.id | struct_name}}ReqAttrWrapper, {% endfor %}optAttrs ...OptionalMetricAttribute) { - options := []metric.AddOption { - {% for attr in attributes | required | without_value %}metric.WithAttributes({{attr.id | arg_name}}.Attribute()),{% endfor %} - } - for _, opt := range optAttrs { - options = append(options, metric.WithAttributes(opt.Attribute())) - } - g.counter.Add(ctx, int64(incr), options...) -} - -func Float64Counter() (*Float64Counter_, error) { - return Float64CounterWithContext(context.TODO()) -} - -func Float64CounterWithContext(ctx context.Context) (*Float64Counter_, error) { - counter, err := client.Meter.Float64Counter( - "{{name}}", - metric.WithDescription("{{brief}}"), - metric.WithUnit("{{unit}}"), - ) - if err != nil { - return nil, err - } - return &Float64Counter_{ - ctx: ctx, - counter: counter, - }, nil -} - -func (g *Float64Counter_) Add(incr float64, {% for attr in attributes | required | without_value %}{{attr.id | arg_name}} {{attr.id | struct_name}}ReqAttrWrapper, {% endfor %}optAttrs ...OptionalMetricAttribute) { - options := []metric.AddOption { - {% for attr in attributes | required | without_value %}metric.WithAttributes({{attr.id | arg_name}}.Attribute()),{% endfor %} - } - for _, opt := range optAttrs { - options = append(options, metric.WithAttributes(opt.Attribute())) - } - g.counter.Add(g.ctx, incr, options...) -} - -func (g *Float64Counter_) AddWithContext(ctx context.Context, incr float64, {% for attr in attributes | required | without_value %}{{attr.id | arg_name}} {{attr.id | struct_name}}ReqAttrWrapper, {% endfor %}optAttrs ...OptionalMetricAttribute) { - options := []metric.AddOption { - {% for attr in attributes | required | without_value %}metric.WithAttributes({{attr.id | arg_name}}.Attribute()),{% endfor %} - } - for _, opt := range optAttrs { - options = append(options, metric.WithAttributes(opt.Attribute())) - } - g.counter.Add(ctx, incr, options...) -} - -// ============================================ -// ===== Asynchronous Counter Declaration ===== -// ============================================ - -func Int64ObservableCounter(observer Int64Observer) error { - _, err := client.Meter.Int64ObservableCounter( - "{{name}}", - metric.WithDescription("{{brief}}"), - metric.WithUnit("{{unit}}"), - metric.WithInt64Callback(func(ctx context.Context, otelObserver metric.Int64Observer) error { - v, {% for attr in attributes | required | without_value %}{{attr.id | arg_name}}, {% endfor %}optAttrs, err := observer() - if err != nil { - return err - } - options := []metric.ObserveOption { - {% for attr in attributes | required | without_value %}metric.WithAttributes({{attr.id | arg_name}}.Attribute()),{% endfor %} - } - for _, opt := range optAttrs { - options = append(options, metric.WithAttributes(opt.Attribute())) - } - otelObserver.Observe(v, options...) - return nil - })) - if err != nil { - return err - } - return nil -} - -func Float64ObservableCounter(observer Float64Observer) error { - _, err := client.Meter.Float64ObservableCounter( - "{{name}}", - metric.WithDescription("{{brief}}"), - metric.WithUnit("{{unit}}"), - metric.WithFloat64Callback(func(ctx context.Context, otelObserver metric.Float64Observer) error { - v, {% for attr in attributes | required | without_value %}{{attr.id | arg_name}}, {% endfor %}optAttrs, err := observer() - if err != nil { - return err - } - options := []metric.ObserveOption { - {% for attr in attributes | required | without_value %}metric.WithAttributes({{attr.id | arg_name}}.Attribute()),{% endfor %} - } - for _, opt := range optAttrs { - options = append(options, metric.WithAttributes(opt.Attribute())) - } - otelObserver.Observe(v, options...) - return nil - })) - if err != nil { - return err - } - return nil -} - -{% elif instrument == "updowncounter" %} -// ===== Synchronous UpDownCounter Declaration ===== -type Int64UpDownCounter_ struct { - ctx context.Context - counter metric.Int64UpDownCounter -} - -type Float64UpDownCounter_ struct { - ctx context.Context - counter metric.Float64UpDownCounter -} - -func Int64UpDownCounter() (*Int64UpDownCounter_, error) { - return Int64UpDownCounterWithContext(context.TODO()) -} - -func Int64UpDownCounterWithContext(ctx context.Context) (*Int64UpDownCounter_, error) { - counter, err := client.Meter.Int64UpDownCounter( - "{{name}}", - metric.WithDescription("{{brief}}"), - metric.WithUnit("{{unit}}"), - ) - if err != nil { - return nil, err - } - return &Int64UpDownCounter_{ - ctx: ctx, - counter: counter, - }, nil -} - -func (g *Int64UpDownCounter_) Add(incr uint64, {% for attr in attributes | required | without_value %}{{attr.id | arg_name}} {{attr.id | struct_name}}ReqAttrWrapper, {% endfor %}optAttrs ...OptionalMetricAttribute) { - options := []metric.AddOption { - {% for attr in attributes | required | without_value %}metric.WithAttributes({{attr.id | arg_name}}.Attribute()),{% endfor %} - } - for _, opt := range optAttrs { - options = append(options, metric.WithAttributes(opt.Attribute())) - } - g.counter.Add(g.ctx, int64(incr), options...) -} - -func (g *Int64UpDownCounter_) AddWithContext(ctx context.Context, incr uint64, {% for attr in attributes | required | without_value %}{{attr.id | arg_name}} {{attr.id | struct_name}}ReqAttrWrapper, {% endfor %}optAttrs ...OptionalMetricAttribute) { - options := []metric.AddOption { - {% for attr in attributes | required | without_value %}metric.WithAttributes({{attr.id | arg_name}}.Attribute()),{% endfor %} - } - for _, opt := range optAttrs { - options = append(options, metric.WithAttributes(opt.Attribute())) - } - g.counter.Add(ctx, int64(incr), options...) -} - -func Float64UpDownCounter() (*Float64UpDownCounter_, error) { - return Float64UpDownCounterWithContext(context.TODO()) -} - -func Float64UpDownCounterWithContext(ctx context.Context) (*Float64UpDownCounter_, error) { - counter, err := client.Meter.Float64UpDownCounter( - "{{name}}", - metric.WithDescription("{{brief}}"), - metric.WithUnit("{{unit}}"), - ) - if err != nil { - return nil, err - } - return &Float64UpDownCounter_{ - ctx: ctx, - counter: counter, - }, nil -} - -func (g *Float64UpDownCounter_) Add(incr float64, {% for attr in attributes | required | without_value %}{{attr.id | arg_name}} {{attr.id | struct_name}}ReqAttrWrapper, {% endfor %}optAttrs ...OptionalMetricAttribute) { - options := []metric.AddOption { - {% for attr in attributes | required | without_value %}metric.WithAttributes({{attr.id | arg_name}}.Attribute()),{% endfor %} - } - for _, opt := range optAttrs { - options = append(options, metric.WithAttributes(opt.Attribute())) - } - g.counter.Add(g.ctx, incr, options...) -} - -func (g *Float64UpDownCounter_) AddWithContext(ctx context.Context, incr float64, {% for attr in attributes | required | without_value %}{{attr.id | arg_name}} {{attr.id | struct_name}}ReqAttrWrapper, {% endfor %}optAttrs ...OptionalMetricAttribute) { - options := []metric.AddOption { - {% for attr in attributes | required | without_value %}metric.WithAttributes({{attr.id | arg_name}}.Attribute()),{% endfor %} - } - for _, opt := range optAttrs { - options = append(options, metric.WithAttributes(opt.Attribute())) - } - g.counter.Add(ctx, incr, options...) -} - -// ============================================ -// ===== Asynchronous UpDownCounter Declaration ===== -// ============================================ - -func Int64ObservableUpDownCounter(observer Int64Observer) error { - _, err := client.Meter.Int64ObservableUpDownCounter( - "{{name}}", - metric.WithDescription("{{brief}}"), - metric.WithUnit("{{unit}}"), - metric.WithInt64Callback(func(ctx context.Context, otelObserver metric.Int64Observer) error { - v, {% for attr in attributes | required | without_value %}{{attr.id | arg_name}}, {% endfor %}optAttrs, err := observer() - if err != nil { - return err - } - options := []metric.ObserveOption { - {% for attr in attributes | required | without_value %}metric.WithAttributes({{attr.id | arg_name}}.Attribute()),{% endfor %} - } - for _, opt := range optAttrs { - options = append(options, metric.WithAttributes(opt.Attribute())) - } - otelObserver.Observe(v, options...) - return nil - })) - if err != nil { - return err - } - return nil -} - -func Float64ObservableUpDownCounter(observer Float64Observer) error { - _, err := client.Meter.Float64ObservableUpDownCounter( - "{{name}}", - metric.WithDescription("{{brief}}"), - metric.WithUnit("{{unit}}"), - metric.WithFloat64Callback(func(ctx context.Context, otelObserver metric.Float64Observer) error { - v, {% for attr in attributes | required | without_value %}{{attr.id | arg_name}}, {% endfor %}optAttrs, err := observer() - if err != nil { - return err - } - options := []metric.ObserveOption { - {% for attr in attributes | required | without_value %}metric.WithAttributes({{attr.id | arg_name}}.Attribute()),{% endfor %} - } - for _, opt := range optAttrs { - options = append(options, metric.WithAttributes(opt.Attribute())) - } - otelObserver.Observe(v, options...) - return nil - })) - if err != nil { - return err - } - return nil -} - -{% elif instrument == "gauge" %} -// ========================================== -// ===== Asynchronous Gauge Declaration ===== -// ========================================== - -func Int64ObservableGauge(observer Int64Observer) error { - _, err := client.Meter.Int64ObservableGauge( - "{{name}}", - metric.WithDescription("{{brief}}"), - metric.WithUnit("{{unit}}"), - metric.WithInt64Callback(func(ctx context.Context, otelObserver metric.Int64Observer) error { - v, {% for attr in attributes | required | without_value %}{{attr.id | arg_name}}, {% endfor %}optAttrs, err := observer() - if err != nil { - return err - } - options := []metric.ObserveOption { - {% for attr in attributes | required | without_value %}metric.WithAttributes({{attr.id | arg_name}}.Attribute()),{% endfor %} - } - for _, opt := range optAttrs { - options = append(options, metric.WithAttributes(opt.Attribute())) - } - otelObserver.Observe(v, options...) - return nil - })) - if err != nil { - return err - } - return nil -} - -func Float64ObservableGauge(observer Float64Observer) error { - _, err := client.Meter.Float64ObservableGauge( - "{{name}}", - metric.WithDescription("{{brief}}"), - metric.WithUnit("{{unit}}"), - metric.WithFloat64Callback(func(ctx context.Context, otelObserver metric.Float64Observer) error { - v, {% for attr in attributes | required | without_value %}{{attr.id | arg_name}}, {% endfor %}optAttrs, err := observer() - if err != nil { - return err - } - options := []metric.ObserveOption { - {% for attr in attributes | required | without_value %}metric.WithAttributes({{attr.id | arg_name}}.Attribute()),{% endfor %} - } - for _, opt := range optAttrs { - options = append(options, metric.WithAttributes(opt.Attribute())) - } - otelObserver.Observe(v, options...) - return nil - })) - if err != nil { - return err - } - return nil -} - -{% elif instrument == "histogram" %} -// ============================================= -// ===== Synchronous Histogram Declaration ===== -// ============================================= - -type Int64Histogram_ struct { - ctx context.Context - histogram metric.Int64Histogram -} - -type Float64Histogram_ struct { - ctx context.Context - histogram metric.Float64Histogram -} - -func Int64Histogram() (*Int64Histogram_, error) { - return Int64HistogramWithContext(context.TODO()) -} - -func Int64HistogramWithContext(ctx context.Context) (*Int64Histogram_, error) { - histogram, err := client.Meter.Int64Histogram( - "{{name}}", - metric.WithDescription("{{brief}}"), - metric.WithUnit("{{unit}}"), - ) - if err != nil { - return nil, err - } - return &Int64Histogram_{ - ctx: ctx, - histogram: histogram, - }, nil -} - -func (g *Int64Histogram_) Record(incr uint64, {% for attr in attributes | required | without_value %}{{attr.id | arg_name}} {{attr.id | struct_name}}ReqAttrWrapper, {% endfor %}optAttrs ...OptionalMetricAttribute) { - options := []metric.RecordOption { - {% for attr in attributes | required | without_value %}metric.WithAttributes({{attr.id | arg_name}}.Attribute()),{% endfor %} - } - for _, opt := range optAttrs { - options = append(options, metric.WithAttributes(opt.Attribute())) - } - g.histogram.Record(g.ctx, int64(incr), options...) -} - -func (g *Int64Histogram_) RecordWithContext(ctx context.Context, incr uint64, {% for attr in attributes | required | without_value %}{{attr.id | arg_name}} {{attr.id | struct_name}}ReqAttrWrapper, {% endfor %}optAttrs ...OptionalMetricAttribute) { - options := []metric.RecordOption { - {% for attr in attributes | required | without_value %}metric.WithAttributes({{attr.id | arg_name}}.Attribute()),{% endfor %} - } - for _, opt := range optAttrs { - options = append(options, metric.WithAttributes(opt.Attribute())) - } - g.histogram.Record(ctx, int64(incr), options...) -} - -func Float64Histogram() (*Float64Histogram_, error) { - return Float64HistogramWithContext(context.TODO()) -} - -func Float64HistogramWithContext(ctx context.Context) (*Float64Histogram_, error) { - histogram, err := client.Meter.Float64Histogram( - "{{name}}", - metric.WithDescription("{{brief}}"), - metric.WithUnit("{{unit}}"), - ) - if err != nil { - return nil, err - } - return &Float64Histogram_{ - ctx: ctx, - histogram: histogram, - }, nil -} - -func (g *Float64Histogram_) Record(incr float64, {% for attr in attributes | required | without_value %}{{attr.id | arg_name}} {{attr.id | struct_name}}ReqAttrWrapper, {% endfor %}optAttrs ...OptionalMetricAttribute) { - options := []metric.RecordOption { - {% for attr in attributes | required | without_value %}metric.WithAttributes({{attr.id | arg_name}}.Attribute()),{% endfor %} - } - for _, opt := range optAttrs { - options = append(options, metric.WithAttributes(opt.Attribute())) - } - g.histogram.Record(g.ctx, incr, options...) -} - -func (g *Float64Histogram_) RecordWithContext(ctx context.Context, incr float64, {% for attr in attributes | required | without_value %}{{attr.id | arg_name}} {{attr.id | struct_name}}ReqAttrWrapper, {% endfor %}optAttrs ...OptionalMetricAttribute) { - options := []metric.RecordOption { - {% for attr in attributes | required | without_value %}metric.WithAttributes({{attr.id | arg_name}}.Attribute()),{% endfor %} - } - for _, opt := range optAttrs { - options = append(options, metric.WithAttributes(opt.Attribute())) - } - g.histogram.Record(ctx, incr, options...) -} - -{% endif %} - -{{ required::declare_attrs(attrs=attributes) }} -{{ optional::declare_attrs(marker="Metric", attrs=attributes) }} diff --git a/templates/go/otel/meter/metric_group.tera b/templates/go/otel/meter/metric_group.tera deleted file mode 100644 index 900dbad2..00000000 --- a/templates/go/otel/meter/metric_group.tera +++ /dev/null @@ -1,20 +0,0 @@ -{% import "required_attrs.macro.tera" as required %} -{% import "optional_attrs.macro.tera" as optional %} -{# Define the file name for the generated code #} -{%- set file_name = name | file_name -%} -{{- config(file_name="otel/meter/metric_group_" ~ file_name ~ "/metric_group.go") -}} -// SPDX-License-Identifier: Apache-2.0 - -package {{ name | file_name }} - -import ( - otel_attr "go.opentelemetry.io/otel/attribute" - - "go_test/pkg/otel/attribute" -) - -type Int64Observer func() (int64, {% for attr in attributes | required | without_value %}{{attr.id | struct_name}}ReqAttrWrapper, {% endfor %}[]OptionalMetricAttribute, error) -type Float64Observer func() (float64, {% for attr in attributes | required | without_value %}{{attr.id | struct_name}}ReqAttrWrapper, {% endfor %}[]OptionalMetricAttribute, error) - -{{ required::declare_attrs(attrs=attributes) }} -{{ optional::declare_attrs(marker="Metric", attrs=attributes) }} diff --git a/templates/go/otel/tracer/span.tera b/templates/go/otel/tracer/span.tera deleted file mode 100644 index 0c4fd4ce..00000000 --- a/templates/go/otel/tracer/span.tera +++ /dev/null @@ -1,160 +0,0 @@ -{% import "required_attrs.macro.tera" as required %} -{% import "optional_attrs.macro.tera" as optional %} -{# Define the file name for the generated code #} -{%- set file_name = span_name | file_name -%} -{{- config(file_name="otel/tracer/" ~ file_name ~ "/span.go") -}} -// SPDX-License-Identifier: Apache-2.0 - -package {{ span_name | file_name }} - -import ( - "context" - - otel_attr "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/codes" - "go.opentelemetry.io/otel/trace" - - client "go_test/pkg/otel" - "go_test/pkg/otel/attribute" -) - -{%- if attributes | required | without_value | length > 0 %} -// Start starts a new `{{ span_name }}` span with -// the given required attributes. -func Start( - {{- required::declare_args(attrs=attributes) }} - optionalAttributes ...{{ optional::attr_type(prefix="Span") }}, -) *{{span_name | struct_name}}Span { - return StartWithContext( - context.TODO(), - {%- for attr in attributes | required | without_value %} - {{attr.id | arg_name}}, - {%- endfor %} - optionalAttributes..., - ) -} - -// StartWithContext starts a new `{{ span_name }}` span with -// the given required attributes and context. -func StartWithContext( - ctx context.Context, - {{- required::declare_args(attrs=attributes) }} - optionalAttributes ...{{ optional::attr_type(prefix="Span") }}, -) *{{span_name | struct_name}}Span { - ctx, span := client.Tracer.Start(ctx, "{{ span_name }}", - {%- for attr in attributes | with_value %} - trace.WithAttributes(attribute.{{ attr.id | function_name }}Key.{{attr.type | type_mapping(enum=attr.id) | function_name}}({{attr.value | value}})), - {%- endfor %} - {%- for attr in attributes | required | without_value %} - trace.WithAttributes({{ attr.id | arg_name }}.Attribute()), - {%- endfor %} - ) - for _, opt := range optionalAttributes { - span.SetAttributes(opt.Attribute()) - } - return &{{span_name | struct_name}}Span { - ctx: ctx, - span: span, - } -} -{%- else %} -// Start starts a new named `{{ span_name }}` span. -func Start{{ span_name | function_name }}(ctx context.Context, optionalAttributes ...{{ optional::attr_type(prefix="Span") }}) *{{span_name | struct_name}}Span { - ctx, span := client.Tracer.Start(ctx, "{{ span_name }}") - for _, opt := range optionalAttributes { - span.SetAttributes(opt.Attribute()) - } - return &{{span_name | struct_name}}Span { - ctx: ctx, - span: span, - } -} -{%- endif %} - -{{ required::declare_attrs(attrs=attributes) }} -{{ optional::declare_attrs(marker="Span", attrs=attributes) }} - -// {{span_name | struct_name}}Span is a span for `{{ span_name }}`. -type {{span_name | struct_name}}Span struct { - ctx context.Context - span trace.Span -} - -{% if events | length > 0 -%} -// {{ span_name | struct_name }}Event is interface implemented by all events for `{{ span_name }}`. -type {{ span_name | struct_name }}Event interface { - EventOptions() []trace.EventOption -} - -{% for event in events -%} - -{% set event_name = event.event_name | function_name -%} -{{ required::declare_attrs(prefix="Event" ~ event_name, attrs=event.attributes) }} -{{ optional::declare_attrs(prefix="Event" ~ event_name, marker="Event" ~ event_name, attrs=event.attributes) }} - -// Event adds an event to the span. -func (s *{{span_name | struct_name}}Span) Event{{ event.event_name | function_name }}( - {%- for attr in event.attributes | required %} - {{attr.id | field_name}} Event{{ event.event_name | function_name }}{{attr.id | struct_name}}ReqAttrWrapper, - {%- endfor %} - optionalAttributes ...{{ optional::attr_type(prefix="Event" ~ event_name) }}, -) *{{span_name | struct_name}}Span { - eventOptions := []trace.EventOption{ - {%- for attr in event.attributes | with_value %} - trace.WithAttributes(attribute.{{ attr.id | function_name }}Key.{{attr.type | type_mapping(enum=attr.id) | function_name}}({{attr.value | value}})), - {%- endfor %} - {%- for attr in event.attributes | required %} - trace.WithAttributes({{ attr.id | field_name }}.Attribute()), - {%- endfor %} - } - for _, opt := range optionalAttributes { - eventOptions = append(eventOptions, trace.WithAttributes(opt.Attribute())) - } - s.span.AddEvent("{{ event.event_name }}", eventOptions...) - return s -} -{% endfor %} - -{%- endif %} - -{% for attr in attributes | not_required | without_value %} -// Attr{{ attr.id | function_name }} sets the optional attribute `{{ attr.id }}` for the span. -// {{ [attr.brief, attr.note, "", "# Examples", attr.examples] | comment(prefix="// ") }} -func (s *{{span_name | struct_name}}Span) {{attr.id | function_name}}OptAttr(value {{ attr.type | type_mapping(enum=attr.id | struct_name) }}) *{{span_name | struct_name}}Span { - s.span.SetAttributes(attribute.{{ attr.id | field_name }}Key.{{ attr.type | type_mapping(enum=attr.id) | function_name }}(value)) - return s -} -{% endfor %} - -func (s *{{span_name | struct_name}}Span) StatusOk() *{{span_name | struct_name}}Span { - s.span.SetStatus(codes.Ok, "") - return s -} - -// Error sets the error for the span. -func (s *{{span_name | struct_name}}Span) Error(err error, description string) *{{span_name | struct_name}}Span { - s.span.SetStatus(codes.Error, description) - s.span.RecordError(err) - return s -} - -// Context returns the context of the current span. -func (s *{{span_name | struct_name }}Span) Context() context.Context { return s.ctx } - -// End ends the span with status OK. -func (s *{{span_name | struct_name}}Span) EndWithOk() { - s.span.SetStatus(codes.Ok, "") - s.span.End() -} - -// End ends the span with status Error and a given description. -func (s *{{span_name | struct_name}}Span) EndWithError(err error, description string) { - s.span.SetStatus(codes.Error, description) - s.span.RecordError(err) - s.span.End() -} - -// End ends the span. -func (s *{{span_name | struct_name}}Span) End() { - s.span.End() -} diff --git a/templates/go/required_attrs.macro.tera b/templates/go/required_attrs.macro.tera deleted file mode 100644 index 793f628b..00000000 --- a/templates/go/required_attrs.macro.tera +++ /dev/null @@ -1,54 +0,0 @@ -{% macro declare_args(attrs) -%} - {%- for attr in attrs | required | without_value %} - {{attr.id | arg_name}} {{attr.id | struct_name}}ReqAttrWrapper, - {%- endfor %} -{% endmacro declare_args %} - - -{% macro declare_attrs(prefix="", attrs) -%} -{% set require_attrs = attrs | required | without_value %} -{% if require_attrs | length > 0 -%} -// =============================================== -// ====== Definition of required attributes ====== -// =============================================== - -{% for attr in require_attrs | without_enum %} -// {{prefix}}{{attr.id | struct_name}}ReqAttr is a wrapper for a required attribute. -// {{ [attr.brief, attr.note, "", "# Examples", attr.examples] | comment(prefix="// ") }} -func {{prefix}}{{attr.id | struct_name}}ReqAttr(v {{ attr.type | type_mapping(enum=attr.id | struct_name) }}) {{prefix}}{{attr.id | struct_name}}ReqAttrWrapper { - return {{prefix}}{{attr.id | struct_name}}ReqAttrWrapper{v} -} -// {{prefix}}{{attr.id | struct_name}}ReqAttrWrapper is a wrapper for the attribute `{{attr.id}}`. -// Use the function {{prefix}}{{attr.id | struct_name}}ReqAttr(value) to create an instance. -type {{prefix}}{{attr.id | struct_name}}ReqAttrWrapper struct { {{ attr.type | type_mapping(enum=attr.id | struct_name) }} } -func (w {{prefix}}{{attr.id | struct_name}}ReqAttrWrapper) Attribute() otel_attr.KeyValue { - return attribute.{{ attr.id | field_name }}Key.String(w.{{ attr.type | type_mapping(enum=attr.id | struct_name) }}) -} - -{% endfor %} - -{% for attr in require_attrs | with_enum %} -// {{prefix}}{{attr.id | struct_name}}ReqAttr is a wrapper for a required attribute. -// {{ [attr.brief, attr.note, "", "# Examples", attr.examples] | comment(prefix="// ") }} -func {{prefix}}{{attr.id | struct_name}}ReqAttr(v {{ attr.type | type_mapping(enum=attr.id | struct_name) }}) {{prefix}}{{attr.id | struct_name}}ReqAttrWrapper { - return {{prefix}}{{attr.id | struct_name}}ReqAttrWrapper{v} -} -// {{prefix}}{{attr.id | struct_name}}ReqAttrWrapper is a wrapper for the attribute `{{attr.id}}`. -// Use the function {{prefix}}{{attr.id | struct_name}}ReqAttr(value) to create an instance. -type {{prefix}}{{attr.id | struct_name}}ReqAttrWrapper struct { {{ attr.type | type_mapping(enum=attr.id | struct_name) }} } -func (w {{prefix}}{{attr.id | struct_name}}ReqAttrWrapper) Attribute() otel_attr.KeyValue { - return attribute.{{ attr.id | field_name }}Key.String(w.{{ attr.type | type_mapping(enum=attr.id | struct_name) }}) -} - -type {{attr.id | struct_name}} string -const ( -{% for variant in attr.type.members %} - // {{variant.id | struct_name}} is a possible value of {{attr.id | struct_name}}. - // {{ [variant.brief, variant.note] | comment(prefix=" // ") }} - {{variant.id | struct_name}} {{attr.id | struct_name}} = "{{variant.id}}" -{%- endfor %} -) -{% endfor %} - -{%- endif %} -{% endmacro declare_attrs %} \ No newline at end of file diff --git a/templates/registry/markdown/attribute_group.md b/templates/registry/markdown/attribute_group.md deleted file mode 100644 index 1fed8404..00000000 --- a/templates/registry/markdown/attribute_group.md +++ /dev/null @@ -1,46 +0,0 @@ -{%- set file_name = ctx.id | file_name -%} -{{- template.set_file_name("attribute_group/" ~ file_name ~ ".md") -}} - -## Group `{{ ctx.id }}` ({{ ctx.type }}) - -### Brief - -{{ ctx.brief | trim }} - -prefix: {{ ctx.prefix }} - -### Attributes - -{% for attribute in ctx.attributes %} -#### Attribute `{{ attribute.name }}` - -{{ attribute.brief }} - -{% if attribute.note %} -{{ attribute.note | trim }} -{% endif %} - -{%- if attribute.requirement_level == "required" %} -- Requirement Level: Required - {%- elif attribute.requirement_level.conditionally_required %} -- Requirement Level: Conditionally Required - {{ attribute.requirement_level.conditionally_required }} - {%- elif attribute.requirement_level == "recommended" %} -- Requirement Level: Recommended - {%- else %} -- Requirement Level: Optional - {%- endif %} - {% if attribute.tag %} -- Tag: {{ attribute.tag }} - {% endif %} - {%- include "attribute_type.j2" %} - {%- include "examples.j2" -%} - {%- if attribute.sampling_relevant %} -- Sampling relevant: {{ attribute.sampling_relevant }} - {%- endif %} - {%- if attribute.deprecated %} -- Deprecated: {{ attribute.deprecated }} - {%- endif %} - {% if attribute.stability %} -- Stability: {{ attribute.stability | capitalize }} - {% endif %} - {% endfor %} diff --git a/templates/registry/markdown/attribute_groups.md b/templates/registry/markdown/attribute_groups.md deleted file mode 100644 index 5cd2168b..00000000 --- a/templates/registry/markdown/attribute_groups.md +++ /dev/null @@ -1,47 +0,0 @@ -# Semantic Convention Attribute Groups - -{% for group in ctx %} -## Group `{{ group.id }}` ({{ group.type }}) - -### Brief - -{{ group.brief | trim }} - -prefix: {{ group.prefix }} - -### Attributes - -{% for attribute in group.attributes %} -#### Attribute `{{ attribute.name }}` - -{{ attribute.brief }} - -{% if attribute.note %} -{{ attribute.note | trim }} -{% endif %} - -{%- if attribute.requirement_level == "required" %} -- Requirement Level: Required - {%- elif attribute.requirement_level.conditionally_required %} -- Requirement Level: Conditionally Required - {{ attribute.requirement_level.conditionally_required }} - {%- elif attribute.requirement_level == "recommended" %} -- Requirement Level: Recommended - {%- else %} -- Requirement Level: Optional - {%- endif %} - {% if attribute.tag %} -- Tag: {{ attribute.tag }} - {% endif %} - {%- include "attribute_type.j2" %} - {%- include "examples.j2" -%} - {%- if attribute.sampling_relevant %} -- Sampling relevant: {{ attribute.sampling_relevant }} - {%- endif %} - {%- if attribute.deprecated %} -- Deprecated: {{ attribute.deprecated }} - {%- endif %} - {% if attribute.stability %} -- Stability: {{ attribute.stability | capitalize }} - {% endif %} - {% endfor %} - {% endfor %} diff --git a/templates/registry/markdown/attribute_type.j2 b/templates/registry/markdown/attribute_type.j2 deleted file mode 100644 index 1c9147ba..00000000 --- a/templates/registry/markdown/attribute_type.j2 +++ /dev/null @@ -1,5 +0,0 @@ -{%- if attribute.type is mapping %} -- Type: Enum [{{ attribute.type.members | map(attribute="value") | join(", ") }}] -{%- else %} -- Type: {{ attribute.type }} -{%- endif %} \ No newline at end of file diff --git a/templates/registry/markdown/event.md b/templates/registry/markdown/event.md deleted file mode 100644 index 43736aa7..00000000 --- a/templates/registry/markdown/event.md +++ /dev/null @@ -1,47 +0,0 @@ -{%- set file_name = ctx.id | file_name -%} -{{- template.set_file_name("event/" ~ file_name ~ ".md") -}} - -# Group `{{ ctx.id }}` ({{ ctx.type }}) - -## Brief - -{{ ctx.brief | trim }} - -Prefix: {{ ctx.prefix }} -Name: {{ ctx.name }} - -## Attributes - -{% for attribute in ctx.attributes %} -### Attribute `{{ attribute.name }}` - -{{ attribute.brief }} - -{% if attribute.note %} -{{ attribute.note | trim }} -{% endif %} - -{%- if attribute.requirement_level == "required" %} -- Requirement Level: Required - {%- elif attribute.requirement_level.conditionally_required %} -- Requirement Level: Conditionally Required - {{ attribute.requirement_level.conditionally_required }} - {%- elif attribute.requirement_level == "recommended" %} -- Requirement Level: Recommended - {%- else %} -- Requirement Level: Optional - {%- endif %} - {% if attribute.tag %} -- Tag: {{ attribute.tag }} - {% endif %} - {%- include "attribute_type.j2" %} - {%- include "examples.j2" -%} - {%- if attribute.sampling_relevant %} -- Sampling relevant: {{ attribute.sampling_relevant }} - {%- endif %} - {%- if attribute.deprecated %} -- Deprecated: {{ attribute.deprecated }} - {%- endif %} - {% if attribute.stability %} -- Stability: {{ attribute.stability | capitalize }} - {% endif %} - {% endfor %} diff --git a/templates/registry/markdown/events.md b/templates/registry/markdown/events.md deleted file mode 100644 index eae78bc1..00000000 --- a/templates/registry/markdown/events.md +++ /dev/null @@ -1,48 +0,0 @@ -# Semantic Convention Event Groups - -{% for group in ctx %} -## Group `{{ group.id }}` ({{ group.type }}) - -### Brief - -{{ group.brief | trim }} - -Prefix: {{ group.prefix }} -Name: {{ group.name }} - -### Attributes - -{% for attribute in group.attributes %} -#### Attribute `{{ attribute.name }}` - -{{ attribute.brief }} - -{% if attribute.note %} -{{ attribute.note | trim }} -{% endif %} - -{%- if attribute.requirement_level == "required" %} -- Requirement Level: Required - {%- elif attribute.requirement_level.conditionally_required %} -- Requirement Level: Conditionally Required - {{ attribute.requirement_level.conditionally_required }} - {%- elif attribute.requirement_level == "recommended" %} -- Requirement Level: Recommended - {%- else %} -- Requirement Level: Optional - {%- endif %} - {% if attribute.tag %} -- Tag: {{ attribute.tag }} - {% endif %} - {%- include "attribute_type.j2" %} - {%- include "examples.j2" -%} - {%- if attribute.sampling_relevant %} -- Sampling relevant: {{ attribute.sampling_relevant }} - {%- endif %} - {%- if attribute.deprecated %} -- Deprecated: {{ attribute.deprecated }} - {%- endif %} - {% if attribute.stability %} -- Stability: {{ attribute.stability | capitalize }} - {% endif %} - {% endfor %} - {% endfor %} diff --git a/templates/registry/markdown/examples.j2 b/templates/registry/markdown/examples.j2 deleted file mode 100644 index 337fc479..00000000 --- a/templates/registry/markdown/examples.j2 +++ /dev/null @@ -1,7 +0,0 @@ -{%- if attribute.examples %} -{%- if attribute.examples is sequence %} -- Examples: {{ attribute.examples | pprint }} -{%- else %} -- Examples: {{ attribute.examples }} -{%- endif %} -{%- endif %} diff --git a/templates/registry/markdown/group.md b/templates/registry/markdown/group.md deleted file mode 100644 index 0fc0685e..00000000 --- a/templates/registry/markdown/group.md +++ /dev/null @@ -1,56 +0,0 @@ -{%- set file_name = ctx.id | file_name -%} -{{- template.set_file_name("group/" ~ file_name ~ ".md") -}} - -# Group `{{ ctx.id }}` ({{ ctx.type }}) - -## Brief - -{{ ctx.brief | trim }} - -prefix: {{ ctx.prefix }} - -## Attributes - -{% for attribute in ctx.attributes %} -### Attribute `{{ attribute.name }}` - -{{ attribute.brief }} - -{% if attribute.note %} -{{ attribute.note | trim }} -{% endif %} - -{%- if attribute.requirement_level == "required" %} -- Requirement Level: Required -{%- elif attribute.requirement_level.conditionally_required %} -- Requirement Level: Conditionally Required - {{ attribute.requirement_level.conditionally_required }} -{%- elif attribute.requirement_level == "recommended" %} -- Requirement Level: Recommended -{%- else %} -- Requirement Level: Optional -{%- endif %} -{% if attribute.tag %} -- Tag: {{ attribute.tag }} -{% endif %} -{%- include "attribute_type.j2" %} -{%- include "examples.j2" -%} -{%- if attribute.sampling_relevant %} -- Sampling relevant: {{ attribute.sampling_relevant }} -{%- endif %} -{%- if attribute.deprecated %} -- Deprecated: {{ attribute.deprecated }} -{%- endif %} -{% if attribute.stability %} -- Stability: {{ attribute.stability | capitalize }} -{% endif %} - -{% if ctx.lineage.attributes %} -{% set attr_lineage = ctx.lineage.attributes[attribute.name] %} -{% if attr_lineage %} -Lineage: -- source group: {{ attr_lineage.source_group }} -- inherited fields: {{ attr_lineage.inherited_fields | join(", ") }} -- locally overridden fields: {{ attr_lineage.locally_overridden_fields | join(", ") }} -{% endif %} -{% endif %} -{% endfor %} \ No newline at end of file diff --git a/templates/registry/markdown/groups.md b/templates/registry/markdown/groups.md deleted file mode 100644 index 056cafd7..00000000 --- a/templates/registry/markdown/groups.md +++ /dev/null @@ -1,56 +0,0 @@ -# Semantic Convention Groups - -{% for group in ctx %} -## Group `{{ group.id }}` ({{ group.type }}) - -### Brief - -{{ group.brief | trim }} - -prefix: {{ group.prefix }} - -### Attributes - -{% for attribute in group.attributes %} -#### Attribute `{{ attribute.name }}` - -{{ attribute.brief }} - -{% if attribute.note %} -{{ attribute.note | trim }} -{% endif %} - -{%- if attribute.requirement_level == "required" %} -- Requirement Level: Required - {%- elif attribute.requirement_level.conditionally_required %} -- Requirement Level: Conditionally Required - {{ attribute.requirement_level.conditionally_required }} - {%- elif attribute.requirement_level == "recommended" %} -- Requirement Level: Recommended - {%- else %} -- Requirement Level: Optional - {%- endif %} - {% if attribute.tag %} -- Tag: {{ attribute.tag }} - {% endif %} - {%- include "attribute_type.j2" %} - {%- include "examples.j2" -%} - {%- if attribute.sampling_relevant %} -- Sampling relevant: {{ attribute.sampling_relevant }} - {%- endif %} - {%- if attribute.deprecated %} -- Deprecated: {{ attribute.deprecated }} - {%- endif %} - {% if attribute.stability %} -- Stability: {{ attribute.stability | capitalize }} - {% endif %} -{% if group.lineage.attributes %} -{% set attr_lineage = group.lineage.attributes[attribute.name] %} -{% if attr_lineage %} -Lineage: -- source group: {{ attr_lineage.source_group }} -- inherited fields: {{ attr_lineage.inherited_fields | join(", ") }} -- locally overridden fields: {{ attr_lineage.locally_overridden_fields | join(", ") }} -{% endif %} -{% endif %} -{% endfor %} -{% endfor %} diff --git a/templates/registry/markdown/groups_per_prefix.md b/templates/registry/markdown/groups_per_prefix.md deleted file mode 100644 index 1639ef1c..00000000 --- a/templates/registry/markdown/groups_per_prefix.md +++ /dev/null @@ -1,50 +0,0 @@ -{%- set file_name = ctx.prefix | file_name -%} -{{- template.set_file_name("prefix/" ~ file_name ~ ".md") -}} - -# Semantic Convention Groups with Prefix `{{ ctx.prefix }}` - -{% for group in ctx.groups %} -## Group `{{ group.id }}` ({{ group.type }}) - -### Brief - -{{ group.brief | trim }} - -prefix: {{ group.prefix }} - -### Attributes - -{% for attribute in group.attributes %} -#### Attribute `{{ attribute.name }}` - -{{ attribute.brief }} - -{% if attribute.note %} -{{ attribute.note | trim }} -{% endif %} - -{%- if attribute.requirement_level == "required" %} -- Requirement Level: Required - {%- elif attribute.requirement_level.conditionally_required %} -- Requirement Level: Conditionally Required - {{ attribute.requirement_level.conditionally_required }} - {%- elif attribute.requirement_level == "recommended" %} -- Requirement Level: Recommended - {%- else %} -- Requirement Level: Optional - {%- endif %} - {% if attribute.tag %} -- Tag: {{ attribute.tag }} - {% endif %} - {%- include "attribute_type.j2" %} - {%- include "examples.j2" -%} - {%- if attribute.sampling_relevant %} -- Sampling relevant: {{ attribute.sampling_relevant }} - {%- endif %} - {%- if attribute.deprecated %} -- Deprecated: {{ attribute.deprecated }} - {%- endif %} - {% if attribute.stability %} -- Stability: {{ attribute.stability | capitalize }} - {% endif %} - {% endfor %} -{% endfor %} diff --git a/templates/registry/markdown/metric.md b/templates/registry/markdown/metric.md deleted file mode 100644 index d45df277..00000000 --- a/templates/registry/markdown/metric.md +++ /dev/null @@ -1,52 +0,0 @@ -{%- set file_name = ctx.id | file_name -%} -{{- template.set_file_name("metric/" ~ file_name ~ ".md") -}} - -## Group `{{ ctx.id }}` ({{ ctx.type }}) - -### Brief - -{{ ctx.brief | trim }} - -{{ ctx.note | trim }} - -Prefix: {{ ctx.prefix }} -Metric: {{ ctx.metric_name }} -Instrument: {{ ctx.instrument }} -Unit: {{ ctx.unit }} -Stability: {{ ctx.stability | capitalize }} - -### Attributes - -{% for attribute in ctx.attributes %} -#### Attribute `{{ attribute.name }}` - -{{ attribute.brief }} - -{% if attribute.note %} -{{ attribute.note | trim }} -{% endif %} - -{%- if attribute.requirement_level == "required" %} -- Requirement Level: Required - {%- elif attribute.requirement_level.conditionally_required %} -- Requirement Level: Conditionally Required - {{ attribute.requirement_level.conditionally_required }} - {%- elif attribute.requirement_level == "recommended" %} -- Requirement Level: Recommended - {%- else %} -- Requirement Level: Optional - {%- endif %} - {% if attribute.tag %} -- Tag: {{ attribute.tag }} - {% endif %} - {%- include "attribute_type.j2" %} - {%- include "examples.j2" -%} - {%- if attribute.sampling_relevant %} -- Sampling relevant: {{ attribute.sampling_relevant }} - {%- endif %} - {%- if attribute.deprecated %} -- Deprecated: {{ attribute.deprecated }} - {%- endif %} - {% if attribute.stability %} -- Stability: {{ attribute.stability | capitalize }} - {% endif %} - {% endfor %} diff --git a/templates/registry/markdown/metrics.md b/templates/registry/markdown/metrics.md deleted file mode 100644 index 641805cb..00000000 --- a/templates/registry/markdown/metrics.md +++ /dev/null @@ -1,53 +0,0 @@ -# Semantic Convention Metric Groups - -{% for group in ctx %} -## Group `{{ group.id }}` ({{ group.type }}) - -### Brief - -{{ group.brief | trim }} - -{{ group.note | trim }} - -Prefix: {{ group.prefix }} -Metric: {{ group.metric_name }} -Instrument: {{ group.instrument }} -Unit: {{ group.unit }} -Stability: {{ group.stability | capitalize }} - -### Attributes - -{% for attribute in group.attributes %} -#### Attribute `{{ attribute.name }}` - -{{ attribute.brief }} - -{% if attribute.note %} -{{ attribute.note | trim }} -{% endif %} - -{%- if attribute.requirement_level == "required" %} -- Requirement Level: Required - {%- elif attribute.requirement_level.conditionally_required %} -- Requirement Level: Conditionally Required - {{ attribute.requirement_level.conditionally_required }} - {%- elif attribute.requirement_level == "recommended" %} -- Requirement Level: Recommended - {%- else %} -- Requirement Level: Optional - {%- endif %} - {% if attribute.tag %} -- Tag: {{ attribute.tag }} - {% endif %} - {%- include "attribute_type.j2" %} - {%- include "examples.j2" -%} - {%- if attribute.sampling_relevant %} -- Sampling relevant: {{ attribute.sampling_relevant }} - {%- endif %} - {%- if attribute.deprecated %} -- Deprecated: {{ attribute.deprecated }} - {%- endif %} - {% if attribute.stability %} -- Stability: {{ attribute.stability | capitalize }} - {% endif %} - {% endfor %} - {% endfor %} diff --git a/templates/registry/markdown/registry.md b/templates/registry/markdown/registry.md deleted file mode 100644 index 3bd4b2c5..00000000 --- a/templates/registry/markdown/registry.md +++ /dev/null @@ -1,52 +0,0 @@ -# Semantic Convention Registry - -Url: {{ registry_url }} - -# Attribute Groups -{% for group in ctx.groups -%} -{%- if group.type == "attribute_group" %} -- [{{ group.id }}](attribute_group/{{ group.id | file_name }}.md) -{%- endif %} -{%- endfor %} - -# Events -{% for group in ctx.groups -%} -{%- if group.type == "event" %} -- [{{ group.id }}](event/{{ group.id | file_name }}.md) - {%- endif %} - {%- endfor %} - -# Metrics -{% for group in ctx.groups -%} -{%- if group.type == "metric" %} -- [{{ group.id }}](metric/{{ group.id | file_name }}.md) -{%- endif %} -{%- endfor %} - -# Metric Groups -{% for group in ctx.groups -%} -{%- if group.type == "metric_group" %} -- [{{ group.id }}](metric_group/{{ group.id | file_name }}.md) - {%- endif %} - {%- endfor %} - -# Resource -{% for group in ctx.groups -%} -{%- if group.type == "resource" %} -- [{{ group.id }}](resource/{{ group.id | file_name }}.md) - {%- endif %} - {%- endfor %} - -# Scope -{% for group in ctx.groups -%} -{%- if group.type == "scope" %} -- [{{ group.id }}](scope/{{ group.id | file_name }}.md) - {%- endif %} - {%- endfor %} - -# Span -{% for group in ctx.groups -%} -{%- if group.type == "span" %} -- [{{ group.id }}](span/{{ group.id | file_name }}.md) - {%- endif %} - {%- endfor %} \ No newline at end of file diff --git a/templates/registry/markdown/resource.md b/templates/registry/markdown/resource.md deleted file mode 100644 index 5fb7efa6..00000000 --- a/templates/registry/markdown/resource.md +++ /dev/null @@ -1,46 +0,0 @@ -{%- set file_name = ctx.id | file_name -%} -{{- template.set_file_name("resource/" ~ file_name ~ ".md") -}} - -## Group `{{ ctx.id }}` ({{ ctx.type }}) - -### Brief - -{{ ctx.brief | trim }} - -prefix: {{ ctx.prefix }} - -### Attributes - -{% for attribute in ctx.attributes %} -#### Attribute `{{ attribute.name }}` - -{{ attribute.brief }} - -{% if attribute.note %} -{{ attribute.note | trim }} -{% endif %} - -{%- if attribute.requirement_level == "required" %} -- Requirement Level: Required - {%- elif attribute.requirement_level.conditionally_required %} -- Requirement Level: Conditionally Required - {{ attribute.requirement_level.conditionally_required }} - {%- elif attribute.requirement_level == "recommended" %} -- Requirement Level: Recommended - {%- else %} -- Requirement Level: Optional - {%- endif %} - {% if attribute.tag %} -- Tag: {{ attribute.tag }} - {% endif %} - {%- include "attribute_type.j2" %} - {%- include "examples.j2" -%} - {%- if attribute.sampling_relevant %} -- Sampling relevant: {{ attribute.sampling_relevant }} - {%- endif %} - {%- if attribute.deprecated %} -- Deprecated: {{ attribute.deprecated }} - {%- endif %} - {% if attribute.stability %} -- Stability: {{ attribute.stability | capitalize }} - {% endif %} - {% endfor %} diff --git a/templates/registry/markdown/resources.md b/templates/registry/markdown/resources.md deleted file mode 100644 index 955b76fc..00000000 --- a/templates/registry/markdown/resources.md +++ /dev/null @@ -1,47 +0,0 @@ -# Semantic Convention Resource Groups - -{% for group in ctx %} -## Group `{{ group.id }}` ({{ group.type }}) - -### Brief - -{{ group.brief | trim }} - -prefix: {{ group.prefix }} - -### Attributes - -{% for attribute in group.attributes %} -#### Attribute `{{ attribute.name }}` - -{{ attribute.brief }} - -{% if attribute.note %} -{{ attribute.note | trim }} -{% endif %} - -{%- if attribute.requirement_level == "required" %} -- Requirement Level: Required - {%- elif attribute.requirement_level.conditionally_required %} -- Requirement Level: Conditionally Required - {{ attribute.requirement_level.conditionally_required }} - {%- elif attribute.requirement_level == "recommended" %} -- Requirement Level: Recommended - {%- else %} -- Requirement Level: Optional - {%- endif %} - {% if attribute.tag %} -- Tag: {{ attribute.tag }} - {% endif %} - {%- include "attribute_type.j2" %} - {%- include "examples.j2" -%} - {%- if attribute.sampling_relevant %} -- Sampling relevant: {{ attribute.sampling_relevant }} - {%- endif %} - {%- if attribute.deprecated %} -- Deprecated: {{ attribute.deprecated }} - {%- endif %} - {% if attribute.stability %} -- Stability: {{ attribute.stability | capitalize }} - {% endif %} - {% endfor %} - {% endfor %} \ No newline at end of file diff --git a/templates/registry/markdown/scope.md b/templates/registry/markdown/scope.md deleted file mode 100644 index e69de29b..00000000 diff --git a/templates/registry/markdown/span.md b/templates/registry/markdown/span.md deleted file mode 100644 index 02b58a3f..00000000 --- a/templates/registry/markdown/span.md +++ /dev/null @@ -1,49 +0,0 @@ -{%- set file_name = ctx.id | file_name -%} -{{- template.set_file_name("span/" ~ file_name ~ ".md") -}} - -## Group `{{ ctx.id }}` ({{ ctx.type }}) - -### Brief - -{{ ctx.brief | trim }} - -{{ ctx.note | trim }} - -Prefix: {{ ctx.prefix }} -Kind: {{ ctx.span_kind }} - -### Attributes - -{% for attribute in ctx.attributes %} -#### Attribute `{{ attribute.name }}` - -{{ attribute.brief }} - -{% if attribute.note %} -{{ attribute.note | trim }} -{% endif %} - -{%- if attribute.requirement_level == "required" %} -- Requirement Level: Required - {%- elif attribute.requirement_level.conditionally_required %} -- Requirement Level: Conditionally Required - {{ attribute.requirement_level.conditionally_required }} - {%- elif attribute.requirement_level == "recommended" %} -- Requirement Level: Recommended - {%- else %} -- Requirement Level: Optional - {%- endif %} - {% if attribute.tag %} -- Tag: {{ attribute.tag }} - {% endif %} - {%- include "attribute_type.j2" %} - {%- include "examples.j2" -%} - {%- if attribute.sampling_relevant %} -- Sampling relevant: {{ attribute.sampling_relevant }} - {%- endif %} - {%- if attribute.deprecated %} -- Deprecated: {{ attribute.deprecated }} - {%- endif %} - {% if attribute.stability %} -- Stability: {{ attribute.stability | capitalize }} - {% endif %} - {% endfor %} \ No newline at end of file diff --git a/templates/registry/markdown/spans.md b/templates/registry/markdown/spans.md deleted file mode 100644 index 28083c2a..00000000 --- a/templates/registry/markdown/spans.md +++ /dev/null @@ -1,50 +0,0 @@ -# Semantic Convention Span Groups - -{% for group in ctx %} -## Group `{{ group.id }}` ({{ group.type }}) - -### Brief - -{{ group.brief | trim }} - -{{ group.note | trim }} - -Prefix: {{ group.prefix }} -Kind: {{ group.span_kind }} - -### Attributes - -{% for attribute in group.attributes %} -#### Attribute `{{ attribute.name }}` - -{{ attribute.brief }} - -{% if attribute.note %} -{{ attribute.note | trim }} -{% endif %} - -{%- if attribute.requirement_level == "required" %} -- Requirement Level: Required - {%- elif attribute.requirement_level.conditionally_required %} -- Requirement Level: Conditionally Required - {{ attribute.requirement_level.conditionally_required }} - {%- elif attribute.requirement_level == "recommended" %} -- Requirement Level: Recommended - {%- else %} -- Requirement Level: Optional - {%- endif %} - {% if attribute.tag %} -- Tag: {{ attribute.tag }} - {% endif %} - {%- include "attribute_type.j2" %} - {%- include "examples.j2" -%} - {%- if attribute.sampling_relevant %} -- Sampling relevant: {{ attribute.sampling_relevant }} - {%- endif %} - {%- if attribute.deprecated %} -- Deprecated: {{ attribute.deprecated }} - {%- endif %} - {% if attribute.stability %} -- Stability: {{ attribute.stability | capitalize }} - {% endif %} - {% endfor %} - {% endfor %} \ No newline at end of file diff --git a/templates/registry/markdown/weaver.yaml b/templates/registry/markdown/weaver.yaml deleted file mode 100644 index b0996d19..00000000 --- a/templates/registry/markdown/weaver.yaml +++ /dev/null @@ -1,43 +0,0 @@ -templates: - - pattern: registry.md - filter: . - application_mode: single - - pattern: attribute_group.md - filter: .groups[] | select(.type == "attribute_group") - application_mode: each - - pattern: attribute_groups.md - filter: .groups[] | select(.type == "attribute_group") - application_mode: single - - pattern: event.md - filter: .groups[] | select(.type == "event") - application_mode: each - - pattern: events.md - filter: .groups[] | select(.type == "event") - application_mode: single - - pattern: group.md - filter: .groups - application_mode: each - - pattern: groups.md - filter: .groups - application_mode: single - - pattern: metric.md - filter: .groups[] | select(.type == "metric") - application_mode: each - - pattern: metrics.md - filter: .groups[] | select(.type == "metric") - application_mode: single - - pattern: resource.md - filter: .groups[] | select(.type == "resource") - application_mode: each - - pattern: resources.md - filter: .groups[] | select(.type == "resource") - application_mode: single - - pattern: span.md - filter: .groups[] | select(.type == "span") - application_mode: each - - pattern: spans.md - filter: .groups[] | select(.type == "span") - application_mode: single - - pattern: groups_per_prefix.md - filter: '.groups | map(select(.prefix != null and .prefix != "")) | group_by(.prefix) | map({prefix: .[0].prefix, groups: .})' - application_mode: each \ No newline at end of file diff --git a/templates/rust/config.yaml b/templates/rust/config.yaml deleted file mode 100644 index 72595c63..00000000 --- a/templates/rust/config.yaml +++ /dev/null @@ -1,15 +0,0 @@ -file_name: snake_case -function_name: snake_case -arg_name: snake_case -struct_name: PascalCase -field_name: snake_case - -type_mapping: - int: i64 - double: f64 - boolean: bool - string: String - "int[]": "[i64]" - "double[]": "[f64]" - "boolean[]": "[bool]" - "string[]": "[String]" \ No newline at end of file diff --git a/templates/rust/eventer/mod.rs.tera b/templates/rust/eventer/mod.rs.tera deleted file mode 100644 index 6de050dc..00000000 --- a/templates/rust/eventer/mod.rs.tera +++ /dev/null @@ -1,19 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 - -//! Generated OTel Client Loggers API. - -{% if schema.resource_events is defined %} -{% for event in schema.resource_events.events %} -/// Events `{{ event.event_name }}` (domain `{{ event.domain }}`) with the given attributes. -pub fn event_{{ event.domain | function_name }}_{{ event.event_name | function_name }}(attrs: {{ event.domain | struct_name }}{{ event.event_name | struct_name }}Attrs) {} - -/// event attributes for `{{ event.event_name }}` (domain `{{ event.domain }}`). -pub struct {{ event.domain | struct_name }}{{ event.event_name | struct_name }}Attrs { - {%- for attr in event.attributes %} - /// {{ [attr.brief, attr.note, "", "# Examples", attr.examples] | comment(prefix=" /// ") }} - pub {{attr.id | field_name}}: {% if attr is required %}{{ attr.type | type_mapping }}{% else %}Option<{{ attr.type | type_mapping }}>{% endif %}, - {%- endfor %} -} - -{% endfor %} -{% endif %} \ No newline at end of file diff --git a/templates/rust/meter/mod.rs.tera b/templates/rust/meter/mod.rs.tera deleted file mode 100644 index d8f75f8f..00000000 --- a/templates/rust/meter/mod.rs.tera +++ /dev/null @@ -1,94 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 - -//! Generated OTel Client Loggers API. - -{% if schema.resource_metrics is defined %} -{% if schema.resource_metrics.metrics is defined %} -{% for metric in schema.resource_metrics.metrics %} -/// Metric `{{ metric.name }}` to report u64 values. -pub fn {{ metric.name | function_name }}_u64() -> {{ metric.name | struct_name }}U64{{ metric.instrument | instrument | struct_name }} { - {{ metric.name | struct_name }}U64{{ metric.instrument | instrument | struct_name }}{} -} - -/// Metric `{{ metric.name }}` to report f64 values. -pub fn {{ metric.name | function_name }}_f64() -> {{ metric.name | struct_name }}F64{{ metric.instrument | instrument | struct_name }} { - {{ metric.name | struct_name }}F64{{ metric.instrument | instrument | struct_name }}{} -} - -pub struct {{ metric.name | struct_name }}U64{{ metric.instrument | instrument | struct_name }} { -} - -pub struct {{ metric.name | struct_name }}F64{{ metric.instrument | instrument | struct_name }} { -} - -impl {{ metric.name | struct_name }}U64{{ metric.instrument | instrument | struct_name }} { - {% if metric.instrument == "counter" %} - pub fn add(&mut self, value: u64, attrs: {{ metric.name | struct_name }}Attrs) {} - {% elif metric.instrument == "updowncounter" %} - pub fn add(&mut self, value: u64, attrs: {{ metric.name | struct_name }}Attrs) {} - {% elif metric.instrument == "gauge" %} - pub fn add(&mut self, value: u64, attrs: {{ metric.name | struct_name }}Attrs) {} - {% elif metric.instrument == "histogram" %} - pub fn record(&mut self, value: u64, attrs: {{ metric.name | struct_name }}Attrs) {} - {% endif %} -} - -impl {{ metric.name | struct_name }}F64{{ metric.instrument | instrument | struct_name }} { - {% if metric.instrument == "counter" %} - pub fn add(&mut self, value: f64, attrs: {{ metric.name | struct_name }}Attrs) {} - {% elif metric.instrument == "updowncounter" %} - pub fn add(&mut self, value: f64, attrs: {{ metric.name | struct_name }}Attrs) {} - {% elif metric.instrument == "gauge" %} - pub fn add(&mut self, value: f64, attrs: {{ metric.name | struct_name }}Attrs) {} - {% elif metric.instrument == "histogram" %} - pub fn record(&mut self, value: f64, attrs: {{ metric.name | struct_name }}Attrs) {} - {% endif %} -} - -/// Metric attributes for `{{ metric.name }}`. -pub struct {{ metric.name | struct_name }}Attrs { - {%- for attr in metric.attributes %} - /// {{ [attr.brief, attr.note, "", "# Examples", attr.examples] | comment(prefix=" /// ") }} - pub {{attr.id | arg_name}}: {% if attr is required %}{{ attr.type | type_mapping }}{% else %}Option<{{ attr.type | type_mapping }}>{% endif %}, - {%- endfor %} -} - -{% endfor %} -{% endif %} -{% endif %} - - -{% if schema.resource_metrics is defined %} -{% if schema.resource_metrics.metric_groups is defined %} -{% for metric in schema.resource_metrics.metric_groups %} -/// Multivariate metric `{{ metric.id }}`. -pub fn {{ metric.id | function_name }}() -> {{ metric.id | struct_name }} { - {{ metric.id | struct_name }}{} -} - -pub struct {{ metric.id | struct_name }} { -} - -impl {{ metric.id | struct_name }} { - pub fn report(&mut self, metrics: {{ metric.id | struct_name }}Metrics, attrs: {{ metric.id | struct_name }}Attrs) {} -} - -/// Multivariate metrics for `{{ metric.id }}`. -pub struct {{ metric.id | struct_name }}Metrics { - {%- for metric in metric.metrics %} - /// {{ [metric.brief, metric.note] | comment(prefix=" /// ") }} - pub {{metric.name | arg_name}}: u64, - {%- endfor %} -} - -/// Metric attributes for `{{ metric.id }}`. -pub struct {{ metric.id | struct_name }}Attrs { - {%- for attr in metric.attributes %} - /// {{ [attr.brief, attr.note, "", "# Examples", attr.examples] | comment(prefix=" /// ") }} - pub {{attr.id | arg_name}}: {% if attr is required %}{{ attr.type | type_mapping }}{% else %}Option<{{ attr.type | type_mapping }}>{% endif %}, - {%- endfor %} -} - -{% endfor %} -{% endif %} -{% endif %} \ No newline at end of file diff --git a/templates/rust/mod.rs.tera b/templates/rust/mod.rs.tera deleted file mode 100644 index 26d821c5..00000000 --- a/templates/rust/mod.rs.tera +++ /dev/null @@ -1,7 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 - -//! Generated OTel Client API. - -pub mod meter; -pub mod eventer; -pub mod tracer; \ No newline at end of file diff --git a/templates/rust/span.tera.bak b/templates/rust/span.tera.bak deleted file mode 100644 index 9cd38e8b..00000000 --- a/templates/rust/span.tera.bak +++ /dev/null @@ -1,142 +0,0 @@ -{# Define the file name for the generated code #} -{%- set file_name = id | file_name -%} -{{- config(file_name="tracers/" ~ file_name ~ ".rs") -}} -// SPDX-License-Identifier: Apache-2.0 - -//! Code generated by OTel Weaver to define the span `{{ id }}`. - -pub enum Status { - Unset, - Error, - Ok, -} - -{%- set required_attrs = attributes | required -%} -{%- set not_required_attrs = attributes | not_required -%} -{%- if required_attrs | length > 0 %} -/// Starts a new named `{{ id }}` span with the given required attributes. -pub fn start( - name: &str, - required_attrs: {{id | struct_name}}Attrs, -) -> {{id | struct_name}}Span { - {{id | struct_name}}Span { - {{id | field_name}}_attrs: required_attrs, - {{id | field_name}}_opt_attrs: Default::default(), - events: Vec::new(), - } -} - -/// Starts a new named `{{ id }}` span with the given required attributes -/// and the optional attributes. -pub fn start_with_opt_attrs( - name: &str, - required_attrs: {{id | struct_name}}Attrs, - optional_attrs: {{id | struct_name}}OptAttrs, - ) -> {{id | struct_name}}Span { - {{id | struct_name}}Span { - {{id | field_name}}_attrs: required_attrs, - {{id | field_name}}_opt_attrs: optional_attrs, - events: Vec::new(), - } -} -{%- else %} -/// Starts a new named `{{ id }}` span. -pub fn start(name: &str) -> {{id | struct_name}}Span { - {{id | struct_name}}Span { - {{id | field_name}}_opt_attrs: {{id | struct_name}}OptAttrs::default(), - } -} - -/// Starts a new named `{{ id }}` span with the given optional attributes. -pub fn start_with_opt_attrs( - name: &str, - optional_attrs: {{id | struct_name}}OptAttrs, - ) -> {{id | struct_name}}Span { - {{id | struct_name}}Span { - {{id | field_name}}_opt_attrs: optional_attrs, - } -} -{%- endif %} - -pub struct {{id | struct_name}}Span { -{%- if required_attrs | length > 0 %} - /// Required span attributes for `{{ id }}`. - {{id | field_name}}_attrs: {{id | struct_name}}Attrs, -{%- endif -%} -{%- if not_required_attrs | length > 0 %} - /// Optional span attributes for `{{ id }}`. - {{id | field_name}}_opt_attrs: {{id | struct_name}}OptAttrs, -{%- endif %} -{%- if events | length > 0 -%} - /// Events for `{{ id }}`. - events: Vec, -{%- endif %} -} - -{% if required_attrs | length > 0 -%} -/// Required span attributes for `{{ id }}`. -pub struct {{id | struct_name}}Attrs { -{%- for attr in required_attrs %} - /// {{ [attr.brief, attr.note, "", "# Examples", attr.examples] | comment(prefix=" /// ") }} - pub {{attr.id | arg_name}}: {{ attr.type | type_mapping }}, -{%- endfor %} -} -{%- endif %} - -{% if not_required_attrs | length > 0 -%} -/// Optional span attributes for `{{ id }}`. -#[derive(Default)] -pub struct {{id | struct_name}}OptAttrs { -{%- for attr in not_required_attrs %} - /// {{ [attr.brief, attr.note, "", "# Examples", attr.examples] | comment(prefix=" /// ") }} - pub {{attr.id | arg_name}}: Option<{{ attr.type | type_mapping }}>, -{%- endfor %} -} -{%- endif %} - -{% if events | length > 0 -%} -pub enum Event { - {% for event in events -%} - {{ event.id | struct_name}} { - {%- for attr in event.attributes %} - /// {{ [attr.brief, attr.note, "", "# Examples", attr.examples] | comment(prefix=" /// ") }} - {%- if attr is required %} - {{attr.id | field_name}}: {{ attr.type | type_mapping }}, - {% else %} - {{attr.id | field_name}}: Option<{{ attr.type | type_mapping }}>, - {% endif -%} - {% endfor %} - }, - {%- endfor %} -} -{%- endif %} - - -impl {{id | struct_name}}Span { - {%- for attr in not_required_attrs %} - /// {{ [attr.brief, attr.note, "", "# Examples", attr.examples] | comment(prefix=" /// ") }} - pub fn attr_{{attr.id | function_name}}(&mut self, value: {{ attr.type | type_mapping }}) { - self.{{id | field_name}}_opt_attrs.{{attr.id | field_name}} = Some(value); - } - {% endfor %} - - {% if events | length > 0 -%} - /// Adds an event to the span. - pub fn event(&mut self, event: Event) { - self.events.push(event); - } - {%- endif %} - - pub fn status(&self, status: Status) {} - pub fn error(&self, err: &dyn std::error::Error) {} - - /// Ends the span. - pub fn end(self) {} - - {%- if not_required_attrs | length > 0 %} - /// Ends the span with the optional attributes. - pub fn end_with_opt_attrs(mut self, optional_attrs: {{id | struct_name}}OptAttrs) { - self.{{id | field_name}}_opt_attrs = optional_attrs; - } - {%- endif %} -} \ No newline at end of file diff --git a/templates/rust/tracer/mod.rs.tera b/templates/rust/tracer/mod.rs.tera deleted file mode 100644 index 2ac39fb3..00000000 --- a/templates/rust/tracer/mod.rs.tera +++ /dev/null @@ -1,142 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 - -//! Generated OTel Client Tracers API. - -pub enum Status { - Unset, - Error, - Ok, -} - -{% if schema.resource_spans is defined %} -{% for span in schema.resource_spans.spans %} - -{%- set required_attrs = span.attributes | required -%} -{%- set not_required_attrs = span.attributes | not_required -%} -{%- if required_attrs | length > 0 %} -/// Starts a new named `{{ span.span_name }}` span with the given required attributes. -pub fn start_{{ span.span_name | function_name }}( - required_attrs: {{span.span_name | struct_name}}Attrs, -) -> {{span.span_name | struct_name}}Span { - {{span.span_name | struct_name}}Span { - {{span.span_name | field_name}}_attrs: required_attrs, - {{span.span_name | field_name}}_opt_attrs: Default::default(), - events: Vec::new(), - } -} - -/// Starts a new named `{{ span.span_name }}` span with the given required attributes -/// and the optional attributes. -pub fn start_{{ span.span_name | function_name }}_with_opt_attrs( - required_attrs: {{span.span_name | struct_name}}Attrs, - optional_attrs: {{span.span_name | struct_name}}OptAttrs, -) -> {{span.span_name | struct_name}}Span { - {{span.span_name | struct_name}}Span { - {{span.span_name | field_name}}_attrs: required_attrs, - {{span.span_name | field_name}}_opt_attrs: optional_attrs, - events: Vec::new(), - } -} -{%- else %} -/// Starts a new named `{{ span.span_name }}` span. -pub fn start_{{ span.span_name | function_name }}() -> {{span.span_name | struct_name}}Span { - {{span.span_name | struct_name}}Span { - {{span.span_name | field_name}}_opt_attrs: {{span.span_name | struct_name}}OptAttrs::default(), - } -} - -/// Starts a new named `{{ span.span_name }}` span with the given optional attributes. -pub fn start_{{ span.span_name | function_name }}_with_opt_attrs( - optional_attrs: {{span.span_name | struct_name}}OptAttrs, -) -> {{span.span_name | struct_name}}Span { - {{span.span_name | struct_name}}Span { - {{span.span_name | field_name}}_opt_attrs: optional_attrs, - } -} -{%- endif %} - -/// {{span.span_name | struct_name}}Span is a span for `{{ span.span_name }}`. -pub struct {{span.span_name | struct_name}}Span { - {%- if required_attrs | length > 0 %} - /// Required span attributes for `{{ span.span_name }}`. - {{span.span_name | field_name}}_attrs: {{span.span_name | struct_name}}Attrs, - {%- endif -%} - {%- if not_required_attrs | length > 0 %} - /// Optional span attributes for `{{ span.span_name }}`. - {{span.span_name | field_name}}_opt_attrs: {{span.span_name | struct_name}}OptAttrs, - {%- endif %} - {%- if span.events | length > 0 %} - /// Events for `{{ span.span_name }}`. - events: Vec<{{ span.span_name | struct_name }}Event>, - {%- endif %} -} - -{% if required_attrs | length > 0 -%} -/// Required span attributes for `{{ span.span_name }}`. -pub struct {{span.span_name | struct_name}}Attrs { - {%- for attr in required_attrs %} - /// {{ [attr.brief, attr.note, "", "# Examples", attr.examples] | comment(prefix=" /// ") }} - pub {{attr.id | field_name}}: {{ attr.type | type_mapping }}, - {%- endfor %} -} -{%- endif %} - -{% if not_required_attrs | length > 0 -%} -/// Optional span attributes for `{{ span.span_name }}`. -#[derive(Default)] -pub struct {{span.span_name | struct_name}}OptAttrs { - {%- for attr in not_required_attrs %} - /// {{ [attr.brief, attr.note, "", "# Examples", attr.examples] | comment(prefix=" /// ") }} - pub {{attr.id | field_name}}: Option<{{ attr.type | type_mapping }}>, - {%- endfor %} -} -{%- endif %} - -{% if span.events | length > 0 -%} -pub enum {{ span.span_name | struct_name }}Event { -{% for event in span.events -%} -{{ event.event_name | struct_name}} { -{%- for attr in event.attributes %} -/// {{ [attr.brief, attr.note, "", "# Examples", attr.examples] | comment(prefix=" /// ") }} -{%- if attr is required %} -{{attr.id | field_name}}: {{ attr.type | type_mapping }}, -{% else %} -{{attr.id | field_name}}: Option<{{ attr.type | type_mapping }}>, -{% endif -%} -{% endfor %} -}, -{%- endfor %} -} -{%- endif %} - - -impl {{span.span_name | struct_name}}Span { - {%- for attr in not_required_attrs %} - /// {{ [attr.brief, attr.note, "", "# Examples", attr.examples] | comment(prefix=" /// ") }} - pub fn attr_{{attr.id | function_name}}(&mut self, value: {{ attr.type | type_mapping }}) { - self.{{span.span_name | field_name}}_opt_attrs.{{attr.id | field_name}} = Some(value); - } - {% endfor %} - - {% if span.events | length > 0 -%} - /// Adds an event to the span. - pub fn event(&mut self, event: {{ span.span_name | struct_name }}Event) { - self.events.push(event); - } - {%- endif %} - - pub fn status(&self, status: Status) {} - pub fn error(&self, err: &dyn std::error::Error) {} - - /// Ends the span. - pub fn end(self) {} - - {%- if not_required_attrs | length > 0 %} - /// Ends the span with the optional attributes. - pub fn end_with_opt_attrs(mut self, optional_attrs: {{span.span_name | struct_name}}OptAttrs) { - self.{{span.span_name | field_name}}_opt_attrs = optional_attrs; - } - {%- endif %} -} -{% endfor %} -{% endif %} \ No newline at end of file