@@ -24,7 +24,10 @@ This is a generated file. DO NOT EDIT.
24
24
import (
25
25
"go.opentelemetry.io/otel/attribute"
26
26
27
- {{ if .TelemetryPackagePath }}"{{ .TelemetryPackagePath }}"{{ end }}
27
+ {{ if .TelemetryPackagePath }}
28
+ {{ if .TelemetryPackageAlias }}{{ .TelemetryPackageAlias }} {{ end -}}
29
+ "{{ .TelemetryPackagePath }}"
30
+ {{ end }}
28
31
)
29
32
30
33
func (d *{{ .StructName }}) Attributes() []attribute.KeyValue {
@@ -43,6 +46,7 @@ var _ {{ .ExportablePackagePrefix }}Exportable = (*{{ .StructName }})(nil)
43
46
type codeGen struct {
44
47
PackageName string
45
48
TelemetryPackagePath string
49
+ TelemetryPackageAlias string
46
50
ExportablePackagePrefix string
47
51
StructName string
48
52
BuildTags string
@@ -98,18 +102,31 @@ func generateCode(writer io.Writer, cfg codeGenConfig) error {
98
102
codeFields = append (codeFields , cf )
99
103
}
100
104
101
- var telemetryPkg string
102
- var exportablePkgPrefix string
105
+ const alias = "ngxTelemetry"
106
+
107
+ var (
108
+ telemetryPkg string
109
+ exportablePkgPrefix string
110
+ telemetryPkgAlias string
111
+ )
103
112
104
113
// check if we generate code for the type in the telemetry package or any other package
105
114
if cfg .packagePath != telemetryPackagePath {
106
115
telemetryPkg = telemetryPackagePath
107
- exportablePkgPrefix = getPackageName (telemetryPackagePath ) + "."
116
+
117
+ // if the name of the package is the same as the telemetry package, we need to use an alias
118
+ if getPackageName (cfg .packagePath ) == getPackageName (telemetryPackagePath ) {
119
+ exportablePkgPrefix = alias + "."
120
+ telemetryPkgAlias = alias
121
+ } else {
122
+ exportablePkgPrefix = getPackageName (telemetryPackagePath ) + "."
123
+ }
108
124
}
109
125
110
126
cg := codeGen {
111
127
PackageName : getPackageName (cfg .packagePath ),
112
128
ExportablePackagePrefix : exportablePkgPrefix ,
129
+ TelemetryPackageAlias : telemetryPkgAlias ,
113
130
TelemetryPackagePath : telemetryPkg ,
114
131
StructName : cfg .typeName ,
115
132
Fields : codeFields ,
0 commit comments