Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [1.1.0-beta.12-wip]

### Changed
- **Internal attribute keys now come from the generated registry enums**
(`Service.*`, `ExceptionAttributes.*`, `Otel.*`) instead of string
literals, across resource creation, exception recording, the
`package:logging` bridge, the OTLP span/log transformers, the sampler,
and the env resource-attribute parsing. A mistyped key is now a compile
error — the same hardening applied to the resource detector after #90.
No wire change: `Enum.key` resolves to the identical registry string.

### Fixed
- **`host.arch` no longer reports the hostname** (#90). The IO resource
detector copy-pasted `Platform.localHostname` into `host.arch`; it now
Expand Down
4 changes: 2 additions & 2 deletions lib/src/environment/otel_env.dart
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,9 @@ class OTelEnv {
final key = pair.substring(0, equalIndex).trim();
final value = pair.substring(equalIndex + 1).trim();

if (key == 'service.name') {
if (key == Service.serviceName.key) {
config['serviceName'] = value;
} else if (key == 'service.version') {
} else if (key == Service.serviceVersion.key) {
config['serviceVersion'] = value;
}
}
Expand Down
8 changes: 4 additions & 4 deletions lib/src/logs/bridge/dart_log_bridge.dart
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,13 @@ class DartLogBridge {
}
if (error != null) {
attributes.add(OTelAPI.attributeString(
'exception.type', error.runtimeType.toString()));
attributes
.add(OTelAPI.attributeString('exception.message', error.toString()));
ExceptionAttributes.exceptionType.key, error.runtimeType.toString()));
attributes.add(OTelAPI.attributeString(
ExceptionAttributes.exceptionMessage.key, error.toString()));
}
if (stackTrace != null) {
attributes.add(OTelAPI.attributeString(
'exception.stacktrace', stackTrace.toString()));
ExceptionAttributes.exceptionStacktrace.key, stackTrace.toString()));
}

// Emit the log
Expand Down
2 changes: 1 addition & 1 deletion lib/src/logs/export/console_log_record_exporter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class ConsoleLogRecordExporter implements LogRecordExporter {
// Format resource
if (logRecord.resource != null) {
final serviceName =
_getResourceAttribute(logRecord.resource!, 'service.name');
_getResourceAttribute(logRecord.resource!, Service.serviceName.key);
if (serviceName != null) {
buffer.write(' service=$serviceName');
}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/logs/export/otlp/log_record_transformer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class OtlpLogRecordTransformer {
if (OTelLog.isDebug()) {
OTelLog.debug('LogRecordTransformer: Extracting resource attributes:');
resourceAttrs.toList().forEach((attr) {
if (attr.key == 'service.name') {
if (attr.key == Service.serviceName.key) {
OTelLog.debug(' ${attr.key}: ${attr.value}');
}
});
Expand Down Expand Up @@ -103,7 +103,7 @@ class OtlpLogRecordTransformer {
/// Get service name from resource attributes.
static String _getResourceServiceName(Attributes attributes) {
for (final attr in attributes.toList()) {
if (attr.key == 'service.name') {
if (attr.key == Service.serviceName.key) {
return attr.value.toString();
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/logs/logger_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class LoggerProvider implements APILoggerProvider {
if (resource != null) {
OTelLog.debug('Resource attributes:');
resource!.attributes.toList().forEach((attr) {
if (attr.key == 'service.name') {
if (attr.key == Service.serviceName.key) {
OTelLog.debug(' ${attr.key}: ${attr.value}');
}
});
Expand Down
10 changes: 5 additions & 5 deletions lib/src/otel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ class OTel {
}

final serviceResourceAttributes = {
'service.name': serviceName,
'service.version': serviceVersion,
Service.serviceName.key: serviceName,
Service.serviceVersion.key: serviceVersion,
};
// Create initial resource with service attributes
var baseResource = OTel.resource(
Expand All @@ -295,7 +295,7 @@ class OTel {
if (OTelLog.isDebug()) {
OTelLog.debug('Resource after platform merge:');
mergedResource.attributes.toList().forEach((attr) {
if (attr.key == 'service.name') {
if (attr.key == Service.serviceName.key) {
OTelLog.debug(' ${attr.key}: ${attr.value}');
}
});
Expand All @@ -309,7 +309,7 @@ class OTel {
if (OTelLog.isDebug()) {
OTelLog.debug('Resource after user attributes merge:');
mergedResource.attributes.toList().forEach((attr) {
if (attr.key == 'service.name') {
if (attr.key == Service.serviceName.key) {
OTelLog.debug(' ${attr.key}: ${attr.value}');
}
});
Expand Down Expand Up @@ -574,7 +574,7 @@ class OTel {
OTelLog.debug('OTel.tracerProvider: Setting resource from default');
if (defaultResource != null) {
defaultResource!.attributes.toList().forEach((attr) {
if (attr.key == 'service.name') {
if (attr.key == Service.serviceName.key) {
OTelLog.debug(' ${attr.key}: ${attr.value}');
}
});
Expand Down
2 changes: 1 addition & 1 deletion lib/src/resource/resource.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class Resource {
if (OTelLog.isDebug()) {
OTelLog.debug('Resource merge result attributes:');
result._attributes.toList().forEach((attr) {
if (attr.key == 'service.name') {
if (attr.key == Service.serviceName.key) {
OTelLog.debug(' ${attr.key}: ${attr.value}');
}
});
Expand Down
6 changes: 3 additions & 3 deletions lib/src/trace/export/otlp/span_transformer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class OtlpSpanTransformer {
if (OTelLog.isDebug()) {
OTelLog.debug('Extracting resource attributes for export:');
resourceAttrs.toList().forEach((attr) {
if (attr.key == 'service.name') {
if (attr.key == Service.serviceName.key) {
OTelLog.debug(' ${attr.key}: ${attr.value}');
}
});
Expand All @@ -49,7 +49,7 @@ class OtlpSpanTransformer {
if (OTelLog.isDebug()) {
OTelLog.debug('Extracting resource attributes for export:');
resourceAttrs.toList().forEach((attr) {
if (attr.key == 'service.name') {
if (attr.key == Service.serviceName.key) {
OTelLog.debug(' ${attr.key}: ${attr.value}');
}
});
Expand Down Expand Up @@ -104,7 +104,7 @@ class OtlpSpanTransformer {
/// Get service name from resource attributes
static String _getResourceServiceName(Attributes attributes) {
for (final attr in attributes.toList()) {
if (attr.key == 'service.name') {
if (attr.key == Service.serviceName.key) {
return attr.value.toString();
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/trace/sampling/counting_sampler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ class ErrorSamplingCondition extends SamplingCondition {
if (attributes == null) return false;

// Check for error status
final statusCode = attributes.getString('otel.status_code');
final statusMessage = attributes.getString('otel.status_description');
final statusCode = attributes.getString(Otel.otelStatusCode.key);
final statusMessage = attributes.getString(Otel.otelStatusDescription.key);

return statusCode == 'ERROR' ||
(statusMessage != null && statusMessage.isNotEmpty);
Expand Down
4 changes: 2 additions & 2 deletions lib/src/trace/tracer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -514,8 +514,8 @@ class Tracer implements APITracer {
error,
stackTrace: sanitized.stackTrace,
attributes: OTel.attributesFromMap(<String, Object>{
'exception.type': sanitized.type,
'exception.message': sanitized.message,
ExceptionAttributes.exceptionType.key: sanitized.type,
ExceptionAttributes.exceptionMessage.key: sanitized.message,
}),
);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/trace/tracer_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ class TracerProvider implements APITracerProvider {
if (resource != null) {
OTelLog.debug('Resource attributes:');
resource!.attributes.toList().forEach((attr) {
if (attr.key == 'service.name') {
if (attr.key == Service.serviceName.key) {
OTelLog.debug(' ${attr.key}: ${attr.value}');
}
});
Expand Down
Loading