-
-
Notifications
You must be signed in to change notification settings - Fork 38
Feat(V3): Support for experimental metrics #1055
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8d821ee
add sample for metrics/ update code and tests
lucas-zimerman e5525dd
initial changelog/ sample app nits
lucas-zimerman 0a8bb80
Merge branch 'V3' of https://github.com/getsentry/sentry-capacitor in…
lucas-zimerman 90ef27f
metrics moved to experimental
lucas-zimerman cbf9042
changelog
lucas-zimerman e83c389
Update CHANGELOG.md
lucas-zimerman 81cb5ab
move sample inside experimental
lucas-zimerman 1e78014
Merge branch 'lz/v3-metrics' of https://github.com/getsentry/sentry-c…
lucas-zimerman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,43 +1,64 @@ | ||
| <!-- SentryCapacitorVue.vue --> | ||
| <script lang="ts"> | ||
| import { IonButton, IonContent, IonFooter, IonHeader, IonTitle, IonToolbar, IonPage } from '@ionic/vue'; | ||
| import { | ||
| IonButton, | ||
| IonContent, | ||
| IonFooter, | ||
| IonHeader, | ||
| IonTitle, | ||
| IonToolbar, | ||
| IonPage, | ||
| } from '@ionic/vue'; | ||
|
|
||
| import * as Sentry from "@sentry/capacitor" | ||
| import * as Sentry from '@sentry/capacitor'; | ||
|
|
||
| export default { | ||
| export default { | ||
| name: 'HomePageView', | ||
| components: { IonButton, IonContent, IonFooter, IonHeader, IonTitle, IonToolbar, IonPage }, | ||
| components: { | ||
| IonButton, | ||
| IonContent, | ||
| IonFooter, | ||
| IonHeader, | ||
| IonTitle, | ||
| IonToolbar, | ||
| IonPage, | ||
| }, | ||
| methods: { | ||
| createMessage() { | ||
| Sentry.captureMessage('Hello VUE'); | ||
| }, | ||
| handledError() { | ||
| try { | ||
| throw Error("A handled error"); | ||
| throw Error('A handled error'); | ||
| } catch (ex) { | ||
| Sentry.captureException(ex); | ||
| } | ||
| }, | ||
| crash() { | ||
| Sentry.nativeCrash(); | ||
| } | ||
| } | ||
| }, | ||
| createMetric() { | ||
| // Create a metric using Sentry metrics API | ||
| Sentry.metrics.count('test.metric.counter', 1, { | ||
| attributes: { from_test_app: true }, | ||
| }); | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
|
|
||
| </script> | ||
|
|
||
| <template> | ||
| <ion-page> | ||
| <ion-header :translucent="true"> | ||
| <ion-toolbar> | ||
| <ion-title>Sentry Capacitor Vue</ion-title> | ||
| </ion-toolbar> | ||
| </ion-header> | ||
| <ion-content :fullscreen="true" class="ion-padding"> | ||
| <ion-button @click="createMessage">Create Message</ion-button> | ||
| <ion-button @click="handledError">Handled Error</ion-button> | ||
| <ion-button @click="crash">Crash</ion-button> | ||
| </ion-content> | ||
| <ion-header :translucent="true"> | ||
| <ion-toolbar> | ||
| <ion-title>Sentry Capacitor Vue</ion-title> | ||
| </ion-toolbar> | ||
| </ion-header> | ||
| <ion-content :fullscreen="true" class="ion-padding"> | ||
| <ion-button @click="createMessage">Create Message</ion-button> | ||
| <ion-button @click="handledError">Handled Error</ion-button> | ||
| <ion-button @click="crash">Crash</ion-button> | ||
| <ion-button @click="createMetric">Create Metric</ion-button> | ||
| </ion-content> | ||
| </ion-page> | ||
| </template> |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,122 @@ | ||
| /* eslint-disable @typescript-eslint/ban-ts-comment */ | ||
| import type { DsnComponents, LogEnvelope, MetricEnvelope, SdkMetadata, SerializedLog, SerializedMetric } from '@sentry/core'; | ||
| import { createEnvelope, dsnToString } from '@sentry/core'; | ||
| import type { LogContainerItem, MetricContainerItem } from '@sentry/core/build/types/types-hoist/envelope'; | ||
|
|
||
|
|
||
| /** | ||
| * Based on packages/core/src/metrics/envelope.ts | ||
| * Creates a metric container envelope item for a list of metrics. | ||
| * | ||
| * @param items - The metrics to include in the envelope. | ||
| * @returns The created metric container envelope item. | ||
| */ | ||
| export function createMetricContainerEnvelopeItem(items: Array<SerializedMetric>): MetricContainerItem { | ||
| return [ | ||
| { | ||
| type: 'trace_metric', | ||
| item_count: items.length, | ||
| content_type: 'application/vnd.sentry.items.trace-metric+json', | ||
| } as MetricContainerItem[0], | ||
| { | ||
| items, | ||
lucas-zimerman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| ]; | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Based on getsentry/sentry-javascript/packages/core/src/logs/envelope.ts | ||
| * Creates a log container envelope item for a list of logs. | ||
| * | ||
| * @param items - The logs to include in the envelope. | ||
| * @returns The created log container envelope item. | ||
| */ | ||
| export function createLogContainerEnvelopeItem(items: Array<SerializedLog>): LogContainerItem { | ||
| return [ | ||
| { | ||
| type: 'log', | ||
| item_count: items.length, | ||
| content_type: 'application/vnd.sentry.items.log+json', | ||
| }, | ||
| { | ||
| items, | ||
| }, | ||
| ]; | ||
| } | ||
|
|
||
| /** | ||
| * Based on getsentry/sentry-javascript/packages/core/src/logs/envelope.ts | ||
| * Creates an envelope for a list of logs. | ||
| * | ||
| * Logs from multiple traces can be included in the same envelope. | ||
| * | ||
| * @param logs - The logs to include in the envelope. | ||
| * @param metadata - The metadata to include in the envelope. | ||
| * @param tunnel - The tunnel to include in the envelope. | ||
| * @param dsn - The DSN to include in the envelope. | ||
| * @returns The created envelope. | ||
| */ | ||
| export function createLogEnvelopeHelper(logs: Array<SerializedLog>, | ||
| metadata?: SdkMetadata, | ||
| tunnel?: string, | ||
| dsn?: DsnComponents, | ||
| ): LogEnvelope { | ||
| const headers: LogEnvelope[0] = {}; | ||
|
|
||
| if (metadata?.sdk) { | ||
| headers.sdk = { | ||
| name: metadata.sdk.name, | ||
| version: metadata.sdk.version, | ||
| }; | ||
| } | ||
|
|
||
| if (!!tunnel && !!dsn) { | ||
| headers.dsn = dsnToString(dsn); | ||
| } | ||
|
|
||
| return createEnvelope<LogEnvelope>(headers, [createLogContainerEnvelopeItem(logs)]); | ||
| } | ||
|
|
||
| /** | ||
| * Based on packages/core/src/metrics/envelope.ts | ||
| * Creates an envelope for a list of metrics. | ||
| * | ||
| * Metrics from multiple traces can be included in the same envelope. | ||
| * | ||
| * @param metrics - The metrics to include in the envelope. | ||
| * @param metadata - The metadata to include in the envelope. | ||
| * @param tunnel - The tunnel to include in the envelope. | ||
| * @param dsn - The DSN to include in the envelope. | ||
| * @returns The created envelope. | ||
| */ | ||
| export function createMetricEnvelopeHelper(metrics: Array<SerializedMetric>, | ||
| metadata?: SdkMetadata, | ||
| tunnel?: string, | ||
| dsn?: DsnComponents): MetricEnvelope { | ||
| const headers: MetricEnvelope[0] = {}; | ||
|
|
||
| if (metadata?.sdk) { | ||
| headers.sdk = { | ||
| name: metadata.sdk.name, | ||
| version: metadata.sdk.version, | ||
| }; | ||
| } | ||
|
|
||
| if (!!tunnel && !!dsn) { | ||
| headers.dsn = dsnToString(dsn); | ||
| } | ||
|
|
||
| return createEnvelope<MetricEnvelope>(headers, [createMetricContainerEnvelopeItem(metrics)]); | ||
| } | ||
|
|
||
|
|
||
| export function base64EnvelopeToString(envelope: string): string | undefined { | ||
| if (!envelope) { | ||
| return undefined; | ||
| } | ||
|
|
||
| const decoded = Buffer.from(envelope, 'base64').toString('utf-8'); | ||
| return decoded; | ||
| } | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.