diff --git a/pkg/semconv/attributes.go b/pkg/semconv/attributes.go index d9718bd7e70..15067e161fe 100644 --- a/pkg/semconv/attributes.go +++ b/pkg/semconv/attributes.go @@ -14,7 +14,7 @@ const ( // RequirementLevel: Optional // Stability: stable // Examples: 'prometheus', 'loki', 'grafana-github-datasource' - GrafanaDatasourceTypeKey = attribute.Key("grafana.datasource.type") + grafanaDatasourceTypeKey = attribute.Key("grafana.datasource.type") // GrafanaDatasourceUidKey is the attribute Key conforming to the // "grafana.datasource.uid" semantic conventions. It represents the @@ -24,21 +24,21 @@ const ( // RequirementLevel: Optional // Stability: stable // Examples: 'abcdefg-123456' - GrafanaDatasourceUidKey = attribute.Key("grafana.datasource.uid") + grafanaDatasourceUidKey = attribute.Key("grafana.datasource.uid") ) // GrafanaDatasourceType returns an attribute KeyValue conforming to the // "grafana.datasource.type" semantic conventions. It represents the datasource // type. func GrafanaDatasourceType(val string) attribute.KeyValue { - return GrafanaDatasourceTypeKey.String(val) + return grafanaDatasourceTypeKey.String(val) } // GrafanaDatasourceUid returns an attribute KeyValue conforming to the // "grafana.datasource.uid" semantic conventions. It represents the datasource // unique identifier. func GrafanaDatasourceUid(val string) attribute.KeyValue { - return GrafanaDatasourceUidKey.String(val) + return grafanaDatasourceUidKey.String(val) } // Describes Grafana data source request attributes. @@ -51,14 +51,14 @@ const ( // RequirementLevel: Optional // Stability: stable // Examples: 3 - GrafanaDatasourceRequestQueryCountKey = attribute.Key("grafana.datasource.request.query_count") + grafanaDatasourceRequestQueryCountKey = attribute.Key("grafana.datasource.request.query_count") ) // GrafanaDatasourceRequestQueryCount returns an attribute KeyValue // conforming to the "grafana.datasource.request.query_count" semantic // conventions. It represents the number of queries in the request. func GrafanaDatasourceRequestQueryCount(val int) attribute.KeyValue { - return GrafanaDatasourceRequestQueryCountKey.Int(val) + return grafanaDatasourceRequestQueryCountKey.Int(val) } // Describes Grafana plugin attributes. @@ -70,7 +70,7 @@ const ( // RequirementLevel: Optional // Stability: stable // Examples: 'prometheus', 'loki', 'grafana-github-datasource' - GrafanaPluginIdKey = attribute.Key("grafana.plugin.id") + grafanaPluginIdKey = attribute.Key("grafana.plugin.id") // GrafanaPluginTypeKey is the attribute Key conforming to the // "grafana.plugin.type" semantic conventions. It represents the plugin @@ -80,24 +80,24 @@ const ( // RequirementLevel: Optional // Stability: stable // Examples: 'datasource' - GrafanaPluginTypeKey = attribute.Key("grafana.plugin.type") + grafanaPluginTypeKey = attribute.Key("grafana.plugin.type") ) var ( // Data Source Plugin - GrafanaPluginTypeDatasource = GrafanaPluginTypeKey.String("datasource") + GrafanaPluginTypeDatasource = grafanaPluginTypeKey.String("datasource") // Panel Plugin - GrafanaPluginTypePanel = GrafanaPluginTypeKey.String("panel") + GrafanaPluginTypePanel = grafanaPluginTypeKey.String("panel") // App Plugin - GrafanaPluginTypeApp = GrafanaPluginTypeKey.String("app") + GrafanaPluginTypeApp = grafanaPluginTypeKey.String("app") // Renderer Plugin - GrafanaPluginTypeRenderer = GrafanaPluginTypeKey.String("renderer") + GrafanaPluginTypeRenderer = grafanaPluginTypeKey.String("renderer") // Secret Manager Plugin - GrafanaPluginTypeSecretmanager = GrafanaPluginTypeKey.String("secretmanager") + GrafanaPluginTypeSecretmanager = grafanaPluginTypeKey.String("secretmanager") ) // GrafanaPluginId returns an attribute KeyValue conforming to the // "grafana.plugin.id" semantic conventions. It represents the plugin ID. func GrafanaPluginId(val string) attribute.KeyValue { - return GrafanaPluginIdKey.String(val) + return grafanaPluginIdKey.String(val) } diff --git a/pkg/semconv/templates/template.j2 b/pkg/semconv/templates/template.j2 index 597c3b7e374..2adae523ee6 100644 --- a/pkg/semconv/templates/template.j2 +++ b/pkg/semconv/templates/template.j2 @@ -20,6 +20,9 @@ {%- macro to_go_attr_type(type, val) -%} {{keyval_method(type)}}({% if type == "string" %}"{{val}}"{% else %}{{val}}{% endif %}) {%- endmacro -%} +{%- macro to_private_go_name(fqn) -%} +{{fqn | replace(".", "_") | replace(" ", "") | to_camelcase }} +{%- endmacro -%} {%- macro to_go_name(fqn) -%} {{fqn | replace(".", " ") | replace("_", " ") | title | replace(" ", "")}} {%- endmacro -%} @@ -74,7 +77,7 @@ Deprecated: {{ attr.brief | replace("Deprecated, ", "") }} // {{ to_go_name(attr.fqn) }} returns an attribute KeyValue conforming to the "{{ attr.fqn }}" semantic conventions. {{ it_reps(attr.brief) }} {%- endif %} {%- endmacro -%} -{%- macro to_go_func(type, name) -%} +{%- macro to_go_func(type, name, keyname) -%} {%- if type == "string" -%} func {{name}}(val string) attribute.KeyValue { {%- elif type == "string[]" -%} @@ -92,7 +95,7 @@ func {{name}}(val bool) attribute.KeyValue { {%- elif type == "boolean[]" -%} func {{name}}(val ...bool) attribute.KeyValue { {%- endif -%} - return {{name}}Key.{{keyval_method(type)}}(val) + return {{keyname}}Key.{{keyval_method(type)}}(val) } {%- endmacro -%} {%- macro sentence_case(text) -%} @@ -111,7 +114,7 @@ const ( {%- for attr in semconvs[semconv].attributes if attr.is_local and not attr.ref and not attr.deprecated %} // {{ keydoc(attr) | wordwrap(72, break_long_words=false, break_on_hyphens=false, wrapstring="\n\t// ") }} // {{ keydetails(attr) | wordwrap(72, break_long_words=false, break_on_hyphens=false, wrapstring="\n\t// ") }} - {{to_go_name(attr.fqn)}}Key = attribute.Key("{{attr.fqn}}") + {{to_private_go_name(attr.fqn)}}Key = attribute.Key("{{attr.fqn}}") {% endfor -%} ) {%- for attr in semconvs[semconv].attributes if attr.is_local and not attr.ref and not attr.deprecated -%} @@ -124,7 +127,7 @@ var ( // // Deprecated: {{ attr.brief | replace("Deprecated, ", "") | wordwrap(76, break_long_words=false, break_on_hyphens=false, wrapstring="\n// ") }} {%- endif %} - {{to_go_name("{}.{}".format(attr.fqn, val.member_id))}} = {{to_go_name(attr.fqn)}}Key.{{to_go_attr_type(attr.attr_type.enum_type, val.value)}} + {{to_go_name("{}.{}".format(attr.fqn, val.member_id))}} = {{to_private_go_name(attr.fqn)}}Key.{{to_go_attr_type(attr.attr_type.enum_type, val.value)}} {%- endfor %} ) {%- endif -%} @@ -133,7 +136,7 @@ var ( {%- if attr.attr_type is string %} {{ fndoc(attr) | wordwrap(76, break_long_words=false, break_on_hyphens=false, wrapstring="\n// ") }} -{{to_go_func(attr.attr_type, to_go_name(attr.fqn))}} +{{to_go_func(attr.attr_type, to_go_name(attr.fqn), to_private_go_name(attr.fqn))}} {%- endif -%} {%- endfor %}