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

feat: implement metrics sdk #415

Merged
merged 5 commits into from
Oct 16, 2019

Conversation

mayurkale22
Copy link
Member

@mayurkale22 mayurkale22 commented Oct 9, 2019

Which problem is this PR solving?

Update 1: Added support for Gauge Metric.
Update 2: Added MeterConfig with Logger option.

packages/opentelemetry-metrics/src/Handle.ts Outdated Show resolved Hide resolved
packages/opentelemetry-metrics/src/Handle.ts Outdated Show resolved Hide resolved
packages/opentelemetry-metrics/src/Handle.ts Outdated Show resolved Hide resolved
distContext?: types.DistributedContext,
spanContext?: types.SpanContext
): void {
throw new Error('not implemented yet');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this just be a no-op since we are saying we don't through errors? (Or maybe log instead?)

packages/opentelemetry-metrics/src/Meter.ts Show resolved Hide resolved
packages/opentelemetry-metrics/src/Meter.ts Outdated Show resolved Hide resolved
packages/opentelemetry-metrics/src/Meter.ts Outdated Show resolved Hide resolved
name: string,
options?: types.MetricOptions
): Metric<GaugeHandle> {
throw new Error('not implemented yet');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log?

packages/opentelemetry-metrics/src/Metric.ts Outdated Show resolved Hide resolved
packages/opentelemetry-metrics/src/Metric.ts Outdated Show resolved Hide resolved
@codecov-io
Copy link

codecov-io commented Oct 9, 2019

Codecov Report

Merging #415 into master will increase coverage by 0.55%.
The diff coverage is 96.03%.

@@            Coverage Diff             @@
##           master     #415      +/-   ##
==========================================
+ Coverage   95.33%   95.89%   +0.55%     
==========================================
  Files         118      114       -4     
  Lines        5852     5599     -253     
  Branches      502      440      -62     
==========================================
- Hits         5579     5369     -210     
+ Misses        273      230      -43
Impacted Files Coverage Δ
packages/opentelemetry-metrics/test/Meter.test.ts 100% <100%> (ø)
packages/opentelemetry-metrics/src/types.ts 100% <100%> (ø)
packages/opentelemetry-metrics/src/Utils.ts 100% <100%> (ø)
packages/opentelemetry-metrics/src/Metric.ts 82.35% <82.35%> (ø)
packages/opentelemetry-metrics/src/Meter.ts 85.71% <85.71%> (ø)
packages/opentelemetry-metrics/src/Handle.ts 93.93% <93.93%> (ø)
...opentelemetry-base/test/resources/resource.test.ts 100% <0%> (ø) ⬆️
...telemetry-plugin-grpc/test/utils/assertionUtils.ts 100% <0%> (ø) ⬆️
...pe-async-hooks/test/AsyncHooksScopeManager.test.ts 100% <0%> (ø) ⬆️
packages/opentelemetry-plugin-dns/src/dns.ts
... and 15 more

name: string,
options?: types.MetricOptions
): Metric<CounterHandle> {
const opt = Object.assign({ monotonic: false, disabled: false }, options);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is { monotonic: false, disabled: false } meant to be the default options? Would it make sense to move it to a DEFAULT_COUNTER_OPTIONS const?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unidirectional needs to be renamed, but monotonic can come from the MetricsOptions: https://github.com/open-telemetry/opentelemetry-js/blob/master/packages/opentelemetry-types/src/metrics/Metric.ts#L60

packages/opentelemetry-metrics/src/Metric.ts Outdated Show resolved Hide resolved
packages/opentelemetry-metrics/src/Metric.ts Outdated Show resolved Hide resolved
import * as types from '@opentelemetry/types';

/**
* CounterHandle is an implementation of the {@link CounterHandle} interface.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment in itself doesn't seem too useful. I'm OK with removing it if needed. (Same applies for comment below)

I guess I was thinking this would instead talk a bit about what a counter is and what a handle is, but maybe the expectation doesn't make sense - perhaps people should just be reading the READMEs anyway.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, tried to update JSDoc comment in e0dcecd. Let me know if this makes sense.

@dyladan
Copy link
Member

dyladan commented Oct 10, 2019

@mayurkale22 fwiw when you force push amendments the PR loses history and I have a hard time seeing what is changed from the previous version. Can you try to keep a history during the PR process and just flatten it before merge? Unless there is some other reason to keep it a single commit.

@mayurkale22
Copy link
Member Author

@mayurkale22 fwiw when you force push amendments the PR loses history and I have a hard time seeing what is changed from the previous version. Can you try to keep a history during the PR process and just flatten it before merge? Unless there is some other reason to keep it a single commit.

I didn't squash the previous comments, commits history is still intact. I had to do force push after rebasing with the master. Anyway, in general I agree with your suggestion.

import { MetricOptions } from './types';

/** This is a SDK implementation of {@link Metric} interface. */
export abstract class Metric<T> implements types.Metric<T> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

* calling this method for each operation.
* @param labelValues the list of label values.
*/
getHandle(labelValues: string[]): T {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think getHandle isn't meant to take labelValues, but an instance of a LabelSet and just be a wrapper around a specific metric.

const labelSet1: LabelSet = meter.defineLabels(labels1)
const labelSet2: LabelSet = meter.defineLabels(labels2)

const counter = meter.createCounter("name");

counter.add(labelSet1, 1); // counter now has 1 for labelSet1

const handle = counter.getHandle(labelSet2);
handle.add(1) // counter has 1 for labelSet2

@dyladan
Copy link
Member

dyladan commented Oct 10, 2019

There were some discussions related to metrics today in the spec and I think it might be in flux. It's hard to tell how they're intending Metric/Handle/Meter to play together. It may be worth taking a look.

const hash = hashLabelValues(labelValues);
if (this._handles.has(hash)) return this._handles.get(hash)!;

const handle = this._makeHandle();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makeHandle, and the handles, should accept the label set/values

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, correct. Done in 7d53d02. Also, added a method to generate TimeSeries from the handle's data + label values.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bg451 I have made the required changes, please take a look again when you get a time.

@mayurkale22
Copy link
Member Author

Per the SIG, we agreed to merge this one and revise later based on Prometheus exporter and end-to-end workflow.

@mayurkale22 mayurkale22 merged commit a025108 into open-telemetry:master Oct 16, 2019
@mayurkale22 mayurkale22 deleted the metrics_sdk branch October 16, 2019 22:42
@mayurkale22 mayurkale22 mentioned this pull request Jun 30, 2020
lukaswelinder pushed a commit to agile-pm/opentelemetry-js that referenced this pull request Jul 24, 2020
…ry#415)

* fix: empty spans when encode failed in HTTPSender

Signed-off-by: himstone.yang <himstone.yang@gmail.com>

* Apply fixes

Signed-off-by: Yuri Shkuro <ys@uber.com>

Co-authored-by: Yuri Shkuro <yurishkuro@users.noreply.github.com>
pichlermarc pushed a commit to dynatrace-oss-contrib/opentelemetry-js that referenced this pull request Dec 15, 2023
Co-authored-by: Bartlomiej Obecny <bobecny@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants