Skip to content

Commit 87379ed

Browse files
committed
feat(metrics): Add public API to collect count, distribution and gauge
1 parent 03afb63 commit 87379ed

File tree

7 files changed

+538
-4
lines changed

7 files changed

+538
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
- Add attributes data to `SentryScope` (#6830)
88
- Add `SentryScope` attributes into log messages (#6834)
9+
- Add `Sentry.metrics.count(..)`, `Sentry.metrics.distribution(..)` and `Sentry.metrics.gauge(..)` to public API (#6957)
910

1011
## 9.0.0
1112

Samples/iOS-Swift/iOS-Swift/Base.lproj/Main.storyboard

Lines changed: 127 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,128 @@
182182
</objects>
183183
<point key="canvasLocation" x="-201" y="1581"/>
184184
</scene>
185+
<!--Metrics-->
186+
<scene sceneID="4rP-dx-RXJ">
187+
<objects>
188+
<viewController title="Metrics" id="WaX-S9-H5w" customClass="MetricsViewController" customModule="iOS_Swift" customModuleProvider="target" sceneMemberID="viewController">
189+
<view key="view" contentMode="scaleToFill" id="OcT-hi-pdF">
190+
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
191+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
192+
<subviews>
193+
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="16" translatesAutoresizingMaskIntoConstraints="NO" id="rmh-6g-Uwz">
194+
<rect key="frame" x="16" y="82" width="288" height="221"/>
195+
<subviews>
196+
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="QaX-3k-ive">
197+
<rect key="frame" x="0.0" y="0.0" width="288" height="63"/>
198+
<subviews>
199+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Counter" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="5rD-Ky-slr">
200+
<rect key="frame" x="0.0" y="0.0" width="288" height="20.5"/>
201+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
202+
<nil key="textColor"/>
203+
<nil key="highlightedColor"/>
204+
</label>
205+
<stackView opaque="NO" contentMode="scaleToFill" spacing="16" translatesAutoresizingMaskIntoConstraints="NO" id="1Wf-Zd-18v">
206+
<rect key="frame" x="0.0" y="28.5" width="288" height="34.5"/>
207+
<subviews>
208+
<textField opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="248" contentHorizontalAlignment="left" contentVerticalAlignment="center" text="1" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="M4h-Hc-tLA">
209+
<rect key="frame" x="0.0" y="0.0" width="217" height="34.5"/>
210+
<fontDescription key="fontDescription" type="system" pointSize="14"/>
211+
<textInputTraits key="textInputTraits" keyboardType="numberPad" returnKeyType="send" enablesReturnKeyAutomatically="YES"/>
212+
</textField>
213+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="QQ0-xy-ux8">
214+
<rect key="frame" x="233" y="0.0" width="55" height="34.5"/>
215+
<state key="normal" title="Button"/>
216+
<buttonConfiguration key="configuration" style="filled" title="Add"/>
217+
<connections>
218+
<action selector="addCountAction:" destination="WaX-S9-H5w" eventType="touchUpInside" id="PUz-Xm-lov"/>
219+
</connections>
220+
</button>
221+
</subviews>
222+
</stackView>
223+
</subviews>
224+
</stackView>
225+
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="axt-EX-EtR">
226+
<rect key="frame" x="0.0" y="79" width="288" height="63"/>
227+
<subviews>
228+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Distribution" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="2Pw-JN-VEg">
229+
<rect key="frame" x="0.0" y="0.0" width="288" height="20.5"/>
230+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
231+
<nil key="textColor"/>
232+
<nil key="highlightedColor"/>
233+
</label>
234+
<stackView opaque="NO" contentMode="scaleToFill" spacing="16" translatesAutoresizingMaskIntoConstraints="NO" id="MiP-Wh-57S">
235+
<rect key="frame" x="0.0" y="28.5" width="288" height="34.5"/>
236+
<subviews>
237+
<textField opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="248" contentHorizontalAlignment="left" contentVerticalAlignment="center" text="123.456" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="3mp-P7-O89">
238+
<rect key="frame" x="0.0" y="0.0" width="217" height="34.5"/>
239+
<fontDescription key="fontDescription" type="system" pointSize="14"/>
240+
<textInputTraits key="textInputTraits" keyboardType="numberPad" returnKeyType="send" enablesReturnKeyAutomatically="YES"/>
241+
</textField>
242+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="IL9-Qq-bGd">
243+
<rect key="frame" x="233" y="0.0" width="55" height="34.5"/>
244+
<state key="normal" title="Button"/>
245+
<buttonConfiguration key="configuration" style="filled" title="Add"/>
246+
<connections>
247+
<action selector="addDistributionAction:" destination="WaX-S9-H5w" eventType="touchUpInside" id="bNm-zz-fVw"/>
248+
</connections>
249+
</button>
250+
</subviews>
251+
</stackView>
252+
</subviews>
253+
</stackView>
254+
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="4aQ-3m-mUI">
255+
<rect key="frame" x="0.0" y="158" width="288" height="63"/>
256+
<subviews>
257+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Gauge" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="0Ak-9b-zCf">
258+
<rect key="frame" x="0.0" y="0.0" width="288" height="20.5"/>
259+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
260+
<nil key="textColor"/>
261+
<nil key="highlightedColor"/>
262+
</label>
263+
<stackView opaque="NO" contentMode="scaleToFill" spacing="16" translatesAutoresizingMaskIntoConstraints="NO" id="hTr-79-QPx">
264+
<rect key="frame" x="0.0" y="28.5" width="288" height="34.5"/>
265+
<subviews>
266+
<textField opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="248" contentHorizontalAlignment="left" contentVerticalAlignment="center" text="789.012" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="aIr-LW-4LC">
267+
<rect key="frame" x="0.0" y="0.0" width="217" height="34.5"/>
268+
<fontDescription key="fontDescription" type="system" pointSize="14"/>
269+
<textInputTraits key="textInputTraits" keyboardType="numberPad" returnKeyType="send" enablesReturnKeyAutomatically="YES"/>
270+
</textField>
271+
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="ye5-tn-KVv">
272+
<rect key="frame" x="233" y="0.0" width="55" height="34.5"/>
273+
<state key="normal" title="Button"/>
274+
<buttonConfiguration key="configuration" style="filled" title="Add"/>
275+
<connections>
276+
<action selector="addGaugeAction:" destination="WaX-S9-H5w" eventType="touchUpInside" id="Daj-FP-6WR"/>
277+
</connections>
278+
</button>
279+
</subviews>
280+
</stackView>
281+
</subviews>
282+
</stackView>
283+
</subviews>
284+
</stackView>
285+
</subviews>
286+
<viewLayoutGuide key="safeArea" id="mLh-yI-XoN"/>
287+
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
288+
<constraints>
289+
<constraint firstItem="mLh-yI-XoN" firstAttribute="top" secondItem="rmh-6g-Uwz" secondAttribute="top" constant="-8" id="K0w-U0-58r"/>
290+
<constraint firstItem="mLh-yI-XoN" firstAttribute="bottom" relation="greaterThanOrEqual" secondItem="rmh-6g-Uwz" secondAttribute="bottom" constant="8" id="Seh-GM-3cK"/>
291+
<constraint firstItem="mLh-yI-XoN" firstAttribute="trailing" secondItem="rmh-6g-Uwz" secondAttribute="trailing" constant="16" id="W39-yc-9za"/>
292+
<constraint firstItem="rmh-6g-Uwz" firstAttribute="leading" secondItem="mLh-yI-XoN" secondAttribute="leading" constant="16" id="y1g-8t-fOf"/>
293+
</constraints>
294+
</view>
295+
<tabBarItem key="tabBarItem" title="Metrics" selectedImage="gauge.with.dots.needle.bottom.0percent" catalog="system" id="muq-gn-YRK"/>
296+
<navigationItem key="navigationItem" title="Metrics" id="Qcp-Xa-u7w"/>
297+
<connections>
298+
<outlet property="counterTextField" destination="M4h-Hc-tLA" id="OU9-Lg-adT"/>
299+
<outlet property="distributionTextField" destination="3mp-P7-O89" id="sdK-YE-ATW"/>
300+
<outlet property="gaugeTextField" destination="aIr-LW-4LC" id="5Bb-t2-xgX"/>
301+
</connections>
302+
</viewController>
303+
<placeholder placeholderIdentifier="IBFirstResponder" id="jCy-yS-T1k" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
304+
</objects>
305+
<point key="canvasLocation" x="-1363" y="2600"/>
306+
</scene>
185307
<!--Profiling-->
186308
<scene sceneID="f4B-j3-STc">
187309
<objects>
@@ -1045,6 +1167,7 @@
10451167
<segue destination="VqS-l1-kwe" kind="relationship" relationship="viewControllers" id="4xB-07-xBR"/>
10461168
<segue destination="NZr-bH-g9o" kind="relationship" relationship="viewControllers" id="QeG-0S-MzX"/>
10471169
<segue destination="aU9-zi-mBa" kind="relationship" relationship="viewControllers" id="w0L-TJ-bTb"/>
1170+
<segue destination="WaX-S9-H5w" kind="relationship" relationship="viewControllers" id="FlP-dO-Q4y"/>
10481171
</connections>
10491172
</tabBarController>
10501173
<placeholder placeholderIdentifier="IBFirstResponder" id="ZEF-L9-zzL" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
@@ -1958,20 +2081,21 @@
19582081
<image name="ellipsis.circle.fill" catalog="system" width="128" height="123"/>
19592082
<image name="exclamationmark.triangle.fill" catalog="system" width="128" height="109"/>
19602083
<image name="flame.fill" catalog="system" width="106" height="128"/>
2084+
<image name="gauge.with.dots.needle.bottom.0percent" catalog="system" width="128" height="123"/>
19612085
<systemColor name="labelColor">
19622086
<color white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
19632087
</systemColor>
19642088
<systemColor name="secondarySystemBackgroundColor">
1965-
<color red="0.94901960780000005" green="0.94901960780000005" blue="0.96862745100000003" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
2089+
<color red="0.94901960784313721" green="0.94901960784313721" blue="0.96862745098039216" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
19662090
</systemColor>
19672091
<systemColor name="systemBackgroundColor">
19682092
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
19692093
</systemColor>
19702094
<systemColor name="systemGray5Color">
1971-
<color red="0.8980392157" green="0.8980392157" blue="0.91764705879999997" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
2095+
<color red="0.89803921568627454" green="0.89803921568627454" blue="0.91764705882352937" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
19722096
</systemColor>
19732097
<systemColor name="systemRedColor">
1974-
<color red="1" green="0.23137254900000001" blue="0.18823529410000001" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
2098+
<color red="1" green="0.2196078431372549" blue="0.23529411764705882" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
19752099
</systemColor>
19762100
</resources>
19772101
</document>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import Sentry
2+
import UIKit
3+
4+
class MetricsViewController: UIViewController {
5+
6+
// MARK: - Interface Builder Outlets
7+
8+
@IBOutlet weak var counterTextField: UITextField!
9+
@IBOutlet weak var distributionTextField: UITextField!
10+
@IBOutlet weak var gaugeTextField: UITextField!
11+
12+
// MARK: - Interface Builder Actions
13+
14+
@IBAction func addCountAction(_ sender: UIButton) {
15+
guard let value = Int(counterTextField.text ?? "0") else { return }
16+
SentrySDK.metrics.count(key: "sample.counter", value: value)
17+
}
18+
19+
@IBAction func addDistributionAction(_ sender: UIButton) {
20+
guard let value = Double(distributionTextField.text ?? "0") else { return }
21+
SentrySDK.metrics.distribution(key: "sample.distribution", value: value)
22+
}
23+
24+
@IBAction func addGaugeAction(_ sender: UIButton) {
25+
guard let value = Double(gaugeTextField.text ?? "0") else { return }
26+
SentrySDK.metrics.gauge(key: "sample.distribution", value: value)
27+
}
28+
}

0 commit comments

Comments
 (0)