Skip to content

Commit e5bf04e

Browse files
committed
Ensure SemanticConvention script doesn't break tests
At the moment, if you run the `generate` script, it will make changes to the project which will cause compiler or test failures. The three failures which this protects against: * The value "int" being used as an enum value. This needs to be "Int" instead. * The keyword "internal" being used as a case value. This should be wrapped with backticks like `internal`. * The Swift telemetry language which we have chosen to add, outside of the specification. While not technically a failure, this change will also revert the documentation changes made in a previous PR which changed all the `Int` values to "int" incorrectly. This fixes that too.
1 parent a03ac38 commit e5bf04e

File tree

3 files changed

+37
-30
lines changed

3 files changed

+37
-30
lines changed

Scripts/semantic-convention/templates/SemanticAttributes.swift.j2

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
Bool
1414
{%- elif type == "number" -%}
1515
Int
16+
{%- elif type == "int" -%}
17+
Int
1618
{%- else -%}
1719
{{type}}
1820
{%- endif -%}
@@ -84,6 +86,11 @@ public enum {{enum}}: String {
8486
*/
8587
public static let {{ member.member_id | to_camelcase }} = {{class_name}}({{ print_value(type, member.value) }})
8688
{%- endfor %}
89+
{%- if 'TelemetrySdkLanguage' in class_name %}
90+
/**
91+
swift.
92+
*/
93+
public static let swift = TelemetrySdkLanguageValues("swift"){% endif %}
8794

8895
internal let value: String
8996

@@ -101,7 +108,7 @@ public enum {{enum}}: String {
101108
/**
102109
{{member.brief | to_doc_brief}}.
103110
*/
104-
case {{ member.member_id | replace(".", "_") }} = {{ print_value(type, member.value) }}
111+
case {{ member.member_id | replace(".", "_") | replace("internal", "`internal`") }} = {{ print_value(type, member.value) }}
105112
{%- endfor %}
106113
}
107114
{% endif %}

Sources/OpenTelemetryApi/Trace/SemanticAttributes.swift

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public enum SemanticAttributes: String {
133133
// Examplesattributes[.netPeerPort] = 80attributes[.netPeerPort] = 8080attributes[.netPeerPort] = 443
134134
~~~
135135

136-
- Requires: Value type should be `int`
136+
- Requires: Value type should be `Int`
137137
*/
138138
case netPeerPort = "net.peer.port"
139139
/**
@@ -173,7 +173,7 @@ public enum SemanticAttributes: String {
173173
// Examplesattributes[.dbCassandraPageSize] = 5000
174174
~~~
175175

176-
- Requires: Value type should be `int`
176+
- Requires: Value type should be `Int`
177177
*/
178178
case dbCassandraPageSize = "db.cassandra.page_size"
179179
/**
@@ -208,7 +208,7 @@ public enum SemanticAttributes: String {
208208
// Examplesattributes[.dbCassandraSpeculativeExecutionCount] = 0attributes[.dbCassandraSpeculativeExecutionCount] = 2
209209
~~~
210210

211-
- Requires: Value type should be `int`
211+
- Requires: Value type should be `Int`
212212
*/
213213
case dbCassandraSpeculativeExecutionCount = "db.cassandra.speculative_execution_count"
214214
/**
@@ -251,7 +251,7 @@ public enum SemanticAttributes: String {
251251
// Examplesattributes[.dbRedisDatabaseIndex] = 0attributes[.dbRedisDatabaseIndex] = 1attributes[.dbRedisDatabaseIndex] = 15
252252
~~~
253253

254-
- Requires: Value type should be `int`
254+
- Requires: Value type should be `Int`
255255
*/
256256
case dbRedisDatabaseIndex = "db.redis.database_index"
257257
/**
@@ -465,7 +465,7 @@ public enum SemanticAttributes: String {
465465
// Examplesattributes[.httpStatusCode] = 200
466466
~~~
467467

468-
- Requires: Value type should be `int`
468+
- Requires: Value type should be `Int`
469469
*/
470470
case httpStatusCode = "http.status_code"
471471
/**
@@ -494,7 +494,7 @@ public enum SemanticAttributes: String {
494494
// Examplesattributes[.httpRequestContentLength] = 3495
495495
~~~
496496

497-
- Requires: Value type should be `int`
497+
- Requires: Value type should be `Int`
498498
*/
499499
case httpRequestContentLength = "http.request_content_length"
500500
/**
@@ -504,7 +504,7 @@ public enum SemanticAttributes: String {
504504
// Examplesattributes[.httpRequestContentLengthUncompressed] = 5493
505505
~~~
506506

507-
- Requires: Value type should be `int`
507+
- Requires: Value type should be `Int`
508508
*/
509509
case httpRequestContentLengthUncompressed = "http.request_content_length_uncompressed"
510510
/**
@@ -514,7 +514,7 @@ public enum SemanticAttributes: String {
514514
// Examplesattributes[.httpResponseContentLength] = 3495
515515
~~~
516516

517-
- Requires: Value type should be `int`
517+
- Requires: Value type should be `Int`
518518
*/
519519
case httpResponseContentLength = "http.response_content_length"
520520
/**
@@ -524,7 +524,7 @@ public enum SemanticAttributes: String {
524524
// Examplesattributes[.httpResponseContentLengthUncompressed] = 5493
525525
~~~
526526

527-
- Requires: Value type should be `int`
527+
- Requires: Value type should be `Int`
528528
*/
529529
case httpResponseContentLengthUncompressed = "http.response_content_length_uncompressed"
530530
/**
@@ -592,7 +592,7 @@ public enum SemanticAttributes: String {
592592
// Examplesattributes[.netHostPort] = 35555
593593
~~~
594594

595-
- Requires: Value type should be `int`
595+
- Requires: Value type should be `Int`
596596
*/
597597
case netHostPort = "net.host.port"
598598
/**
@@ -774,7 +774,7 @@ public enum SemanticAttributes: String {
774774
// Examplesattributes[.messagingMessagePayloadSizeBytes] = 2738
775775
~~~
776776

777-
- Requires: Value type should be `int`
777+
- Requires: Value type should be `Int`
778778
*/
779779
case messagingMessagePayloadSizeBytes = "messaging.message_payload_size_bytes"
780780
/**
@@ -784,7 +784,7 @@ public enum SemanticAttributes: String {
784784
// Examplesattributes[.messagingMessagePayloadCompressedSizeBytes] = 2048
785785
~~~
786786

787-
- Requires: Value type should be `int`
787+
- Requires: Value type should be `Int`
788788
*/
789789
case messagingMessagePayloadCompressedSizeBytes = "messaging.message_payload_compressed_size_bytes"
790790
/**
@@ -900,7 +900,7 @@ public enum SemanticAttributes: String {
900900
// Examplesattributes[.threadId] = 42
901901
~~~
902902

903-
- Requires: Value type should be `int`
903+
- Requires: Value type should be `Int`
904904
*/
905905
case threadId = "thread.id"
906906
/**
@@ -954,7 +954,7 @@ public enum SemanticAttributes: String {
954954
// Examplesattributes[.codeLineno] = 42
955955
~~~
956956

957-
- Requires: Value type should be `int`
957+
- Requires: Value type should be `Int`
958958
*/
959959
case codeLineno = "code.lineno"
960960
/**
@@ -1073,7 +1073,7 @@ public enum SemanticAttributes: String {
10731073
// Examplesattributes[.awsDynamodbLimit] = 10
10741074
~~~
10751075

1076-
- Requires: Value type should be `int`
1076+
- Requires: Value type should be `Int`
10771077
*/
10781078
case awsDynamodbLimit = "aws.dynamodb.limit"
10791079
/**
@@ -1148,7 +1148,7 @@ public enum SemanticAttributes: String {
11481148
// Examplesattributes[.awsDynamodbTableCount] = 20
11491149
~~~
11501150

1151-
- Requires: Value type should be `int`
1151+
- Requires: Value type should be `Int`
11521152
*/
11531153
case awsDynamodbTableCount = "aws.dynamodb.table_count"
11541154
/**
@@ -1164,7 +1164,7 @@ public enum SemanticAttributes: String {
11641164
// Examplesattributes[.awsDynamodbSegment] = 10
11651165
~~~
11661166

1167-
- Requires: Value type should be `int`
1167+
- Requires: Value type should be `Int`
11681168
*/
11691169
case awsDynamodbSegment = "aws.dynamodb.segment"
11701170
/**
@@ -1174,7 +1174,7 @@ public enum SemanticAttributes: String {
11741174
// Examplesattributes[.awsDynamodbTotalSegments] = 100
11751175
~~~
11761176

1177-
- Requires: Value type should be `int`
1177+
- Requires: Value type should be `Int`
11781178
*/
11791179
case awsDynamodbTotalSegments = "aws.dynamodb.total_segments"
11801180
/**
@@ -1184,7 +1184,7 @@ public enum SemanticAttributes: String {
11841184
// Examplesattributes[.awsDynamodbCount] = 10
11851185
~~~
11861186

1187-
- Requires: Value type should be `int`
1187+
- Requires: Value type should be `Int`
11881188
*/
11891189
case awsDynamodbCount = "aws.dynamodb.count"
11901190
/**
@@ -1194,7 +1194,7 @@ public enum SemanticAttributes: String {
11941194
// Examplesattributes[.awsDynamodbScannedCount] = 50
11951195
~~~
11961196

1197-
- Requires: Value type should be `int`
1197+
- Requires: Value type should be `Int`
11981198
*/
11991199
case awsDynamodbScannedCount = "aws.dynamodb.scanned_count"
12001200
/**
@@ -1287,7 +1287,7 @@ public enum SemanticAttributes: String {
12871287
// Examplesattributes[.messagingKafkaPartition] = 2
12881288
~~~
12891289

1290-
- Requires: Value type should be `int`
1290+
- Requires: Value type should be `Int`
12911291
*/
12921292
case messagingKafkaPartition = "messaging.kafka.partition"
12931293
/**
@@ -1299,7 +1299,7 @@ public enum SemanticAttributes: String {
12991299
/**
13001300
The [numeric status code](https://github.com/grpc/grpc/blob/v1.33.2/doc/statuscodes.md) of the gRPC request.
13011301

1302-
- Requires: Value type should be `int`
1302+
- Requires: Value type should be `Int`
13031303
*/
13041304
case rpcGrpcStatusCode = "rpc.grpc.status_code"
13051305
/**
@@ -1334,7 +1334,7 @@ public enum SemanticAttributes: String {
13341334
// Examplesattributes[.rpcJsonrpcErrorCode] = -32700attributes[.rpcJsonrpcErrorCode] = 100
13351335
~~~
13361336

1337-
- Requires: Value type should be `int`
1337+
- Requires: Value type should be `Int`
13381338
*/
13391339
case rpcJsonrpcErrorCode = "rpc.jsonrpc.error_code"
13401340
/**
@@ -1360,19 +1360,19 @@ public enum SemanticAttributes: String {
13601360

13611361
- Note: This way we guarantee that the values will be consistent between different implementations.
13621362

1363-
- Requires: Value type should be `int`
1363+
- Requires: Value type should be `Int`
13641364
*/
13651365
case messageId = "message.id"
13661366
/**
13671367
Compressed size of the message in bytes.
13681368

1369-
- Requires: Value type should be `int`
1369+
- Requires: Value type should be `Int`
13701370
*/
13711371
case messageCompressedSize = "message.compressed_size"
13721372
/**
13731373
Uncompressed size of the message in bytes.
13741374

1375-
- Requires: Value type should be `int`
1375+
- Requires: Value type should be `Int`
13761376
*/
13771377
case messageUncompressedSize = "message.uncompressed_size"
13781378

@@ -2047,4 +2047,4 @@ public enum SemanticAttributes: String {
20472047
case received = "RECEIVED"
20482048
}
20492049

2050-
}
2050+
}

Sources/OpenTelemetrySdk/Resources/ResourceAttributes.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ public enum ResourceAttributes: String {
370370

371371
- Note: It's recommended to set this attribute since e.g. too little memory can easily stop a Java AWS Lambda function from working correctly. On AWS Lambda, the environment variable `AWS_LAMBDA_FUNCTION_MEMORY_SIZE` provides this information.
372372

373-
- Requires: Value type should be `int`
373+
- Requires: Value type should be `Int`
374374
*/
375375
case faasMaxMemory = "faas.max_memory"
376376
/**
@@ -705,7 +705,7 @@ public enum ResourceAttributes: String {
705705
// Examplesattributes[.processPid] = 1234
706706
~~~
707707

708-
- Requires: Value type should be `int`
708+
- Requires: Value type should be `Int`
709709
*/
710710
case processPid = "process.pid"
711711
/**

0 commit comments

Comments
 (0)