-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from Workiva/O11Y-2256
O11Y-2256 : Resource can be passed into MeterProvider
- Loading branch information
Showing
10 changed files
with
159 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
@experimental | ||
library experimental_api; | ||
|
||
import 'package:meta/meta.dart'; | ||
|
||
export 'api/metrics/counter.dart' show Counter; | ||
export 'api/metrics/meter_provider.dart' show MeterProvider; | ||
export 'api/metrics/meter.dart' show Meter; | ||
export 'api/metrics/noop/noop_meter.dart' show NoopMeter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
@experimental | ||
library experimental_sdk; | ||
|
||
import 'package:meta/meta.dart'; | ||
|
||
export 'sdk/metrics/counter.dart' show Counter; | ||
export 'sdk/metrics/meter_provider.dart' show MeterProvider; | ||
export 'sdk/metrics/meter.dart' show Meter; | ||
export 'sdk/resource/resource.dart' show Resource; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import 'package:opentelemetry/api.dart' as api; | ||
|
||
class InstrumentationScope { | ||
final String _name; | ||
final String _version; | ||
final String _schemaUrl; | ||
final List<api.Attribute> _attributes; | ||
|
||
InstrumentationScope( | ||
this._name, this._version, this._schemaUrl, this._attributes); | ||
|
||
String get name { | ||
return _name; | ||
} | ||
|
||
String get version { | ||
return _version; | ||
} | ||
|
||
String get schemaUrl { | ||
return _schemaUrl; | ||
} | ||
|
||
List<api.Attribute> get attributes { | ||
return _attributes; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
lib/src/sdk/metrics/state/meter_provider_shared_state.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import 'package:opentelemetry/sdk.dart'; | ||
import 'package:opentelemetry/src/sdk/common/instrumentation_scope.dart'; | ||
import 'package:opentelemetry/src/sdk/metrics/state/meter_shared_state.dart'; | ||
import 'package:quiver/core.dart'; | ||
|
||
int instrumentationScopeId(InstrumentationScope instrumentationScope) { | ||
return hash3(instrumentationScope.name, instrumentationScope.version, | ||
instrumentationScope.schemaUrl); | ||
} | ||
|
||
class MeterProviderSharedState { | ||
Resource resource; | ||
final Map<int, MeterSharedState> _meterSharedStates = {}; | ||
|
||
MeterProviderSharedState(this.resource); | ||
|
||
MeterSharedState getMeterSharedState( | ||
InstrumentationScope instrumentationScope) { | ||
final id = instrumentationScopeId(instrumentationScope); | ||
var meterSharedState = _meterSharedStates[id]; | ||
if (meterSharedState == null) { | ||
meterSharedState = MeterSharedState(this, instrumentationScope); | ||
_meterSharedStates[id] = meterSharedState; | ||
} | ||
return meterSharedState; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import 'package:opentelemetry/src/sdk/common/instrumentation_scope.dart'; | ||
|
||
import 'package:opentelemetry/src/experimental_sdk.dart' as sdk; | ||
|
||
import 'meter_provider_shared_state.dart'; | ||
|
||
class MeterSharedState { | ||
// ignore: unused_field | ||
final MeterProviderSharedState _meterProviderSharedState; | ||
// ignore: unused_field | ||
final InstrumentationScope _instrumentationScope; | ||
sdk.Meter meter; | ||
|
||
MeterSharedState(this._meterProviderSharedState, this._instrumentationScope) { | ||
meter = sdk.Meter(this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
test/unit/sdk/metrics/state/instrumentation_scope_id_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
@TestOn('vm') | ||
|
||
import 'package:logging/logging.dart'; | ||
import 'package:opentelemetry/api.dart'; | ||
import 'package:opentelemetry/src/sdk/common/instrumentation_scope.dart'; | ||
import 'package:opentelemetry/src/sdk/metrics/state/meter_provider_shared_state.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
group('instrumentationScopeId:', () { | ||
setUp(() { | ||
Logger.root.level = Level.ALL; // defaults to Level.INFO | ||
Logger.root.onRecord.listen((record) { | ||
printOnFailure( | ||
'${record.level.name}: ${record.time}: ${record.message}'); | ||
}); | ||
}); | ||
|
||
test('instrumentationScopeId with same parameters returns same id', () { | ||
//int instrumentationScopeId(InstrumentationScope instrumentationScope) { | ||
const nameOne = 'testName'; | ||
const versionOne = ''; | ||
const schemaUrlOne = ''; | ||
const attributesOne = <Attribute>[]; | ||
|
||
const nameTwo = 'testName'; | ||
const versionTwo = ''; | ||
const schemaUrlTwo = ''; | ||
const attributesTwo = <Attribute>[]; | ||
|
||
final scopeOne = InstrumentationScope( | ||
nameOne, versionOne, schemaUrlOne, attributesOne); | ||
final idOne = instrumentationScopeId(scopeOne); | ||
|
||
final scopeTwo = InstrumentationScope( | ||
nameTwo, versionTwo, schemaUrlTwo, attributesTwo); | ||
final idTwo = instrumentationScopeId(scopeTwo); | ||
|
||
expect(idOne, equals(idTwo)); | ||
}); | ||
}); | ||
} |