Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate collector semconv codegen to weaver #11064

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
28 changes: 23 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,33 @@ genpdata:
$(GOCMD) run pdata/internal/cmd/pdatagen/main.go
$(MAKE) fmt

# Definitions for semconvgen
DOCKER_USER=$(shell id -u):$(shell id -g)
# TODO - Pull docker image versions from rennovate-friendly source, e.g.
# $(shell cat dependencies.Dockerfile | awk '$$4=="weaver" {print $$2}')
WEAVER_CONTAINER=otel/weaver:v0.9.1


# Generate semantic convention constants. Requires a clone of the opentelemetry-specification repo
gensemconv: $(SEMCONVGEN) $(SEMCONVKIT)
gensemconv: $(SEMCONVKIT)
@[ "${SPECPATH}" ] || ( echo ">> env var SPECPATH is not set"; exit 1 )
@[ "${SPECTAG}" ] || ( echo ">> env var SPECTAG is not set"; exit 1 )
@echo "Generating semantic convention constants from specification version ${SPECTAG} at ${SPECPATH}"
$(SEMCONVGEN) -o semconv/${SPECTAG} -t semconv/template.j2 -s ${SPECTAG} -i ${SPECPATH}/model/. --only=resource -p conventionType=resource -f generated_resource.go
$(SEMCONVGEN) -o semconv/${SPECTAG} -t semconv/template.j2 -s ${SPECTAG} -i ${SPECPATH}/model/. --only=event -p conventionType=event -f generated_event.go
$(SEMCONVGEN) -o semconv/${SPECTAG} -t semconv/template.j2 -s ${SPECTAG} -i ${SPECPATH}/model/. --only=span -p conventionType=trace -f generated_trace.go
$(SEMCONVGEN) -o semconv/${SPECTAG} -t semconv/template.j2 -s ${SPECTAG} -i ${SPECPATH}/model/. --only=attribute_group -p conventionType=attribute_group -f generated_attribute_group.go
mkdir -p $(PWD)/semconv/${SPECTAG}
docker run --rm \
-u $(DOCKER_USER) \
--mount 'type=bind,source=$(PWD)/semconv/weaver,target=/home/weaver/templates,readonly' \
--mount 'type=bind,source=$(SPECPATH)/model,target=/home/weaver/source,readonly' \
--mount 'type=bind,source=$(PWD)/semconv/${SPECTAG},target=/home/weaver/target' \
$(WEAVER_CONTAINER) registry generate \
--registry=/home/weaver/source \
--templates=/home/weaver/templates \
collector \
/home/weaver/target
# $(SEMCONVGEN) -o semconv/${SPECTAG} -t semconv/template.j2 -s ${SPECTAG} -i ${SPECPATH}/model/. --only=resource -p conventionType=resource -f generated_resource.go
# $(SEMCONVGEN) -o semconv/${SPECTAG} -t semconv/template.j2 -s ${SPECTAG} -i ${SPECPATH}/model/. --only=event -p conventionType=event -f generated_event.go
# $(SEMCONVGEN) -o semconv/${SPECTAG} -t semconv/template.j2 -s ${SPECTAG} -i ${SPECPATH}/model/. --only=span -p conventionType=trace -f generated_trace.go
# $(SEMCONVGEN) -o semconv/${SPECTAG} -t semconv/template.j2 -s ${SPECTAG} -i ${SPECPATH}/model/. --only=attribute_group -p conventionType=attribute_group -f generated_attribute_group.go
$(SEMCONVKIT) -output "semconv/$(SPECTAG)" -tag "$(SPECTAG)"

# Checks that the HEAD of the contrib repo checked out in CONTRIB_PATH compiles
Expand Down
81 changes: 0 additions & 81 deletions semconv/template.j2

This file was deleted.

75 changes: 75 additions & 0 deletions semconv/weaver/registry/collector/attribute_group.go.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{# TODO - move to built in support for language constants in weaver #}
{%- macro to_go_name(fqn) -%}
{{fqn | replace(".", " ") | replace("_", " ") | title | replace(" ", "")}}
{%- endmacro -%}
{%- macro requirement_level_doc(attr) -%}
{%- if attr.requirement_level == "required" -%}
Requirement Level: Required
{% elif attr.requirement_level.conditionally_required %}
Requirement Level: Conditionally Required - {{ attr.requirement_level.conditionally_required }}
{%- elif attr.requirement_level == "recommended" -%}
Requirement Level: Recommended
{% elif attr.requirement_level.recommended %}
Requirement Level: Recommended - {{ attr.requirement_level.recommended }}
{%- else -%}
Requirement Level: Optional
{%- endif %}
{%- endmacro -%}
{%- macro deprecated_doc(attr) -%}
{% if attr is deprecated %}Deprecated: {{ attr.deprecated }}{% endif %}
{%- endmacro -%}
{%- macro notes_doc(attr) -%}
{% if attr.note %}Note: {{ attr.note }}{% endif %}
{%- endmacro -%}
{%- macro examples_doc(attr) -%}
{%- if attr.examples is iterable %}
Examples: {{ attr.examples | pprint | trim("[]") }}
{%- endif -%}
{%- endmacro -%}
{%- macro godoc(attr) -%}
{{ attr.brief }}
Stability: {{ attr.stability | title }}
{% if attr is enum %}Type: Enum{% else %}Type: {{ attr.type | instantiated_type }}{% endif %}
{{ requirement_level_doc(attr) }}
{{ deprecated_doc(attr) }}
{{ examples_doc(attr) }}
{{ notes_doc(attr) }}
{%- endmacro -%}
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

// Code generated from semantic convention specification. DO NOT EDIT.

package semconv

{% for group in ctx %}
{% if group.attributes | length > 0 %}
{# TODO - we're grouping by registry namespace, not attribute gorup, so we lose group docs #}
jsuereth marked this conversation as resolved.
Show resolved Hide resolved
{{ ["Namespace: " ~ group.root_namespace] | comment }}
const (
{% for attribute in group.attributes %}
{{ godoc(attribute) | comment(indent=4) }}
Attribute{{to_go_name(attribute.name)}} = "{{attribute.name}}"
{% endfor %}
)
{% for attribute in group.attributes | select("enum") %}
{# TODO - Previously, non-string enums were not handled #}
{% if (attribute.type | instantiated_type) == "string" %}
{{ ["Enum values for " ~ attribute.name] | comment}}
const (
{%- for val in attribute.type.members %}
{{ val.brief | comment }}
Attribute{{to_go_name(attribute.name ~ "." ~ val.id)}} = "{{val.value}}"
{%- endfor %}
)
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}

func GetAttribute_groupSemanticConventionAttributeNames() []string() {
return []string(
{% for group in ctx %}{% for attribute in group.attributes %}Attribute{{to_go_name(attribute.name)}}
{% endfor %}{% endfor %}
)
}
10 changes: 10 additions & 0 deletions semconv/weaver/registry/collector/event.go.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

// Code generated from semantic convention specification. DO NOT EDIT.

package semconv

func GetEventSemanticConventionAttributeNames() []string {
return []string{}
}
10 changes: 10 additions & 0 deletions semconv/weaver/registry/collector/resource.go.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

// Code generated from semantic convention specification. DO NOT EDIT.

package semconv

func GetResourceSemanticConventionAttributeNames() []string {
return []string{}
}
10 changes: 10 additions & 0 deletions semconv/weaver/registry/collector/trace.go.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

// Code generated from semantic convention specification. DO NOT EDIT.

package semconv

func GetTraceSemanticConventionAttributeNames() []string {
return []string{}
}
136 changes: 136 additions & 0 deletions semconv/weaver/registry/collector/weaver.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
templates:
- pattern: resource.go.j2
filter: >
.groups
| map(select(.type == "resource"))
| map(. + {root_namespace: (if .id | index(".") then .id | split(".") | .[1] else "other" end)})
| sort_by(.root_namespace)
application_mode: single
file_name: generated_resource.go
- pattern: event.go.j2
filter: >
.groups
| map(select(.type == "event"))
| map(. + {root_namespace: (if .id | index(".") then .id | split(".") | .[1] else "other" end)})
| sort_by(.root_namespace)
application_mode: single
file_name: generated_event.go
- pattern: trace.go.j2
filter: >
.groups
| map(select(.type == "trace"))
jsuereth marked this conversation as resolved.
Show resolved Hide resolved
| map(. + {root_namespace: (if .id | index(".") then .id | split(".") | .[1] else "other" end)})
| sort_by(.root_namespace)
file_name: generated_trace.go
application_mode: single
- pattern: attribute_group.go.j2
filter: >
semconv_grouped_attributes({
"exclude_deprecated": false
})
application_mode: single
file_name: generated_attribute_group.go
comment_formats:
go:
format: markdown
prefix: "// "
indent_first_level_list_items: true
shortcut_reference_link: true
trim: true
remove_trailing_dots: true
default_comment_format: go
acronyms:
- ACL
- AIX
- AKS
- AMD64
- API
- ARM32
- ARM64
- ARN
- ARNs
- ASCII
- AWS
- CPP
- CPU
- CSS
- DB
- DC
- DNS
- EC2
- ECS
- EDB
- EKS
- EOF
- GCP
- GRPC
- GUID
- HPUX
- HSQLDB
- HTML
- HTTP
- HTTPS
- IA64
- ID
- IP
- JDBC
- JSON
- K8S
- LHS
- MSSQL
- OS
- PHP
- PID
- PPC32
- PPC64
- QPS
- QUIC
- RAM
- RHS
- RPC
- SDK
- SLA
- SMTP
- SPDY
- SQL
- SSH
- TCP
- TLS
- TTL
- UDP
- UID
- UI
- UUID
- URI
- URL
- UTF8
- VM
- XML
- XMPP
- XSRF
- XSS
- ZOS
- CronJob
- DaemonSet
- StatefulSet
- ReplicaSet
- WebEngine
- MySQL
- PostgreSQL
- MariaDB
- MaxDB
- FirstSQL
- InstantDB
- HBase
- MongoDB
- CouchDB
- CosmosDB
- DynamoDB
- HanaDB
- FreeBSD
- NetBSD
- OpenBSD
- DragonflyBSD
- InProc
- FaaS
- OTel
Loading