Skip to content

Commit 95537a8

Browse files
feat(logs): Add support for logs (#920)
* add support for logs * add changelog
1 parent 98a0b6c commit 95537a8

File tree

14 files changed

+134
-7
lines changed

14 files changed

+134
-7
lines changed

CHANGELOG.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,45 @@
88
99
## Unreleased
1010

11+
#### Features
12+
13+
- Add experimental support for Log tracing ([#920](https://github.com/getsentry/sentry-capacitor/pull/920))
14+
15+
To enable it add the following code to your Sentry Options:
16+
17+
```typescript
18+
Sentry.init({
19+
// other options...
20+
_experiments: {
21+
enableLogs: true,
22+
},
23+
});
24+
```
25+
26+
You can also filter the logs being collected by adding beforeSendLogs into `_experiments`
27+
28+
```typescript
29+
Sentry.init({
30+
// other options...
31+
_experiments: {
32+
enableLogs: true,
33+
beforeSendLog: log => {
34+
return log;
35+
},
36+
},
37+
});
38+
```
39+
1140
### Dependencies
1241

1342
- Bump Android SDK from v8.13.2 to v8.13.3 ([#919](https://github.com/getsentry/sentry-capacitor/pull/919))
1443
- [changelog](https://github.com/getsentry/sentry-java/blob/main/CHANGELOG.md#8133)
1544
- [diff](https://github.com/getsentry/sentry-java/compare/8.13.2...8.13.3)
1645

46+
### Self Hosted
47+
48+
- It is recommended to use Sentry Self Hosted version `25.2.0` or new for Sentry Capacitor V2 or newer
49+
1750
## 2.0.0-beta.2
1851

1952
### Features

android/src/main/java/io/sentry/capacitor/SentryCapacitor.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ public void initNativeSdk(final PluginCall call) {
144144
}
145145
}
146146

147+
options.getLogs().setEnabled(Boolean.TRUE.equals(capOptions.getBoolean("enableLogs", false)));
148+
147149
logger.info(String.format("Native Integrations '%s'", options.getIntegrations().toString()));
148150
}
149151
);

example/ionic-angular-v6/src/app/app.module.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ Sentry.init(
4444
// If the entire session is not sampled, use the below sample rate to sample
4545
// sessions when an error occurs.
4646
replaysOnErrorSampleRate: 1.0,
47+
_experiments: {
48+
enableLogs: true,
49+
beforeSendLog: (log) => {
50+
return log;
51+
}
52+
},
4753
},
4854
sentryAngularInit,
4955
);

example/ionic-angular-v6/src/app/tab2/tab2.page.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@
4040
>
4141
</label>
4242

43+
<label>
44+
Capture Log
45+
<ion-button (click)="captureLog()"
46+
>CaptureLog</ion-button
47+
>
48+
</label>
49+
4350
<label>
4451
Close the SDK
4552
<ion-button (click)="close()"

example/ionic-angular-v6/src/app/tab2/tab2.page.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ export class Tab2Page {
3838
);
3939
}
4040

41+
public captureLog(): void {
42+
Sentry.logger.info('hello world capacitor');
43+
Sentry.logger.warn('hello world capacitor');
44+
Sentry.logger.error('hello world capacitor');
45+
Sentry.logger.fatal('hello world capacitor', {
46+
customAttribute: 1234,
47+
complexAttribute: { logged: true}
48+
});
49+
}
50+
4151
public close(): void {
4252
Sentry.close();
4353
}

example/ionic-angular-v7/src/app/app.module.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ Sentry.init(
2929
blockAllMedia: true,
3030
}),
3131
],
32+
_experiments: {
33+
enableLogs: true,
34+
beforeSendLog: (log) => {
35+
return log;
36+
}
37+
},
3238
// A release identifier
3339
release: '1.0.0',
3440
// A dist identifier

example/ionic-angular-v7/src/app/tab2/tab2.page.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@
4040
>
4141
</label>
4242

43+
<label>
44+
Capture Log
45+
<ion-button (click)="captureLog()"
46+
>CaptureLog</ion-button
47+
>
48+
</label>
49+
4350
<label>
4451
Close the SDK
4552
<ion-button (click)="close()"

example/ionic-angular-v7/src/app/tab2/tab2.page.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ export class Tab2Page {
3838
);
3939
}
4040

41+
public captureLog(): void {
42+
Sentry.logger.info('hello world capacitor');
43+
Sentry.logger.warn('hello world capacitor');
44+
Sentry.logger.error('hello world capacitor');
45+
Sentry.logger.fatal('hello world capacitor', {
46+
customAttribute: 1234,
47+
complexAttribute: { logged: true}
48+
});
49+
}
50+
4151
public close(): void {
4252
Sentry.close();
4353
}

example/ionic-vue3/src/main.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ Sentry.init({
5252
// Session Replay
5353
replaysSessionSampleRate: 0.1, // This sets the sample rate at 10%. You may want to change it to 100% while in development and then sample at a lower rate in production.
5454
replaysOnErrorSampleRate: 1.0, // If you're not already sampling the entire session, change the sample rate to 100% when sampling sessions where errors occur.
55+
_experiments: {
56+
enableLogs: true,
57+
beforeSendLog: (log) => {
58+
return log;
59+
}
60+
},
61+
5562
},
5663
// Forward the init method from @sentry/vue
5764
SentryVue.init

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export {
4848
startIdleSpan,
4949
} from '@sentry/core';
5050

51-
export { replayIntegration, browserTracingIntegration, registerSpanErrorInstrumentation } from '@sentry/browser';
51+
export { replayIntegration, browserTracingIntegration, registerSpanErrorInstrumentation, logger } from '@sentry/browser';
5252

5353
export { SDK_NAME, SDK_VERSION } from './version';
5454
export type { CapacitorOptions } from './options';

0 commit comments

Comments
 (0)