Skip to content

RUMM-2700: Use event write context in WebView Logs#1121

Merged
0xnm merged 1 commit into
feature/sdkv2from
nogorodnikov/rumm-2700/use-eventwritecontext-for-logs
Nov 4, 2022
Merged

RUMM-2700: Use event write context in WebView Logs#1121
0xnm merged 1 commit into
feature/sdkv2from
nogorodnikov/rumm-2700/use-eventwritecontext-for-logs

Conversation

@0xnm

@0xnm 0xnm commented Nov 2, 2022

Copy link
Copy Markdown
Member

What does this PR do?

This change brings usage of event write context (EWC) to the WebView Logs feature. The approach is similar to what was done before in #1117, #1106, #1103, etc.

There is one non-related change though: in WebViewLogEventConsumer the order of event processing is changed: now it is first checked for the proper type, then mapped instead of the opposite (otherwise we may map events which are not going to be written).

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Make sure you discussed the feature or bugfix with the maintaining team in an Issue
  • Make sure each commit and the PR mention the Issue number (cf the CONTRIBUTING doc)

@0xnm
0xnm requested a review from a team as a code owner November 2, 2022 15:05
@xgouchet xgouchet added the size-large This PR is large sized label Nov 2, 2022
Base automatically changed from nogorodnikov/rumm-2699/remove-rumeventsourceprovider to feature/sdkv2 November 3, 2022 08:55
@codecov-commenter

codecov-commenter commented Nov 3, 2022

Copy link
Copy Markdown

Codecov Report

Merging #1121 (991ace4) into feature/sdkv2 (0bab8ec) will increase coverage by 0.09%.
The diff coverage is 92.68%.

@@                Coverage Diff                @@
##           feature/sdkv2    #1121      +/-   ##
=================================================
+ Coverage          82.43%   82.52%   +0.09%     
=================================================
  Files                348      347       -1     
  Lines              11380    11355      -25     
  Branches            1911     1912       +1     
=================================================
- Hits                9380     9370      -10     
+ Misses              1419     1412       -7     
+ Partials             581      573       -8     
Impacted Files Coverage Δ
.../com/datadog/android/webview/DatadogEventBridge.kt 80.00% <75.00%> (+1.05%) ⬆️
...id/webview/internal/rum/WebViewRumEventConsumer.kt 84.78% <87.50%> (ø)
...id/webview/internal/log/WebViewLogEventConsumer.kt 86.36% <93.75%> (-2.01%) ⬇️
.../kotlin/com/datadog/android/v2/core/DatadogCore.kt 88.83% <100.00%> (ø)
.../webview/internal/storage/WebViewLogsDataWriter.kt 100.00% <100.00%> (ø)
...android/webview/internal/log/WebViewLogsFeature.kt 100.00% <100.00%> (ø)
...android/log/internal/logger/TelemetryLogHandler.kt 75.00% <0.00%> (-25.00%) ⬇️
...in/com/datadog/android/log/internal/LogsFeature.kt 88.71% <0.00%> (-3.23%) ⬇️
.../android/rum/internal/domain/scope/RumViewScope.kt 96.61% <0.00%> (-0.20%) ⬇️
...src/main/kotlin/com/datadog/android/DatadogSite.kt 86.67% <0.00%> (ø)
... and 10 more

offset = timeProvider.getServerOffsetMillis()
offsets[viewId] = offset
offset = datadogContext.time.serverTimeOffsetMs
synchronized(offsets) { offsets[viewId] = offset }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why do you use synchronized block here ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

because offsets field can be accessed from the different threads (it gets called from EWC, which can be invoked on the different worker threads), so we need to make the work with this field thread-safe.

The work happens on the worker thread anyway, so synchronisation penalty is not important.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, I had that one before but then looked under the hood and noticed that Android uses a SingleThreadExecutor for the JS bridge, I tested it also and made sure we only have one thread there.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see the reason now actually with the new architecture, good point.

try {
val viewId = offsets.entries.first()
offsets.remove(viewId.key)
synchronized(offsets) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

same here

@0xnm
0xnm merged commit e32754e into feature/sdkv2 Nov 4, 2022
@0xnm
0xnm deleted the nogorodnikov/rumm-2700/use-eventwritecontext-for-logs branch November 4, 2022 09:47
@xgouchet xgouchet added this to the 1.16.0 milestone Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size-large This PR is large sized

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants