Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

O11Y-2256 : Resource can be passed into MeterProvider #90

Merged
merged 7 commits into from
Dec 3, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
O11Y-2256: code cleanup
  • Loading branch information
dustinlessard-wf committed Nov 30, 2022
commit 60c27429566236f0a734c66785bbc6cfc21d0191
3 changes: 0 additions & 3 deletions lib/src/experimental_sdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,4 @@ 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/metrics/state/meter_shared_state.dart' show MeterSharedState;
export 'sdk/metrics/state/meter_provider_shared_state.dart'
show MeterProviderSharedState;
export 'sdk/resource/resource.dart' show Resource;
4 changes: 3 additions & 1 deletion lib/src/sdk/metrics/meter.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import 'package:opentelemetry/src/experimental_sdk.dart' as sdk;
import 'package:opentelemetry/src/experimental_api.dart' as api;

import 'state/meter_shared_state.dart';

class Meter implements api.Meter {
// ignore: unused_field
final sdk.MeterSharedState _state;
final MeterSharedState _state;

Meter(this._state);

Expand Down
15 changes: 5 additions & 10 deletions lib/src/sdk/metrics/state/meter_provider_shared_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,23 @@ import 'package:opentelemetry/src/sdk/metrics/state/meter_shared_state.dart';
import 'package:quiver/core.dart';

int instrumentationScopeId(InstrumentationScope instrumentationScope) {
return hash4(
instrumentationScope.name,
instrumentationScope.version,
instrumentationScope.schemaUrl,
instrumentationScope.attributes.isEmpty
? const []
: instrumentationScope.attributes);
return hash3(instrumentationScope.name, instrumentationScope.version,
instrumentationScope.schemaUrl);
}

class MeterProviderSharedState {
Resource resource;
Map<int, MeterSharedState> meterSharedStates = {};
final Map<int, MeterSharedState> _meterSharedStates = {};

MeterProviderSharedState(this.resource);

MeterSharedState getMeterSharedState(
InstrumentationScope instrumentationScope) {
final id = instrumentationScopeId(instrumentationScope);
var meterSharedState = meterSharedStates[id];
var meterSharedState = _meterSharedStates[id];
if (meterSharedState == null) {
meterSharedState = MeterSharedState(this, instrumentationScope);
meterSharedStates[id] = meterSharedState;
_meterSharedStates[id] = meterSharedState;
}
return meterSharedState;
}
Expand Down
4 changes: 3 additions & 1 deletion lib/src/sdk/metrics/state/meter_shared_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ 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 sdk.MeterProviderSharedState _meterProviderSharedState;
final MeterProviderSharedState _meterProviderSharedState;
// ignore: unused_field
final InstrumentationScope _instrumentationScope;
sdk.Meter meter;
Expand Down