Skip to content

[Feat][SDK- 431] Add threads information to payload #327

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 37 commits into from
May 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
bbbf5e5
fix: typos
christianbuon Mar 23, 2025
08e1d60
feat: add new class RollbarThread
christianbuon Mar 24, 2025
337a1f1
feat: set thread information from RollbarUncaughtExceptionHandler
christianbuon Mar 24, 2025
c3ee843
feat: add Exception Thread and other threads information
christianbuon Mar 24, 2025
e73ab61
feat: add Threads to body
christianbuon Mar 24, 2025
2bfb85d
feat: add Threads to throwable wrapper in notifier
christianbuon Mar 24, 2025
bdb79d5
refactor: a Thread should only contain trace_chain, not trace
christianbuon Mar 28, 2025
a645a62
refactor: add a list of groups before threads in payload
christianbuon Mar 29, 2025
1889b0f
refactor: simplify truncation in TelemetryEvents
christianbuon Mar 29, 2025
9953f08
refactor: add truncation to TelemetryEvents in body
christianbuon Mar 29, 2025
34e252f
refactor: add truncation helper method for a list with Truncatable ob…
christianbuon Mar 29, 2025
62c038b
refactor: truncate Group in body
christianbuon Mar 30, 2025
162c253
refactor: set expected payload, first threads, with a group of trace_…
christianbuon Mar 30, 2025
68659a9
refactor: remove locals field in a Trace from a non exception thread
christianbuon Mar 31, 2025
1090987
chore: fix indentation
christianbuon Mar 31, 2025
c9384a7
chore: remove * from import
christianbuon Mar 31, 2025
2bc8148
chore: add Java doc and fix indentations
christianbuon Mar 31, 2025
f191a89
chore: add Java doc and fix indentations
christianbuon Mar 31, 2025
a7e5a2d
chore: fix lint
christianbuon Mar 31, 2025
8a7f7c8
chore: fix lint
christianbuon Apr 6, 2025
315f7c4
chore: add revapi info
christianbuon Apr 6, 2025
5363108
feat: add threads to a catch exception log
christianbuon Apr 7, 2025
e95f991
chore: fix lint, line max size exceeded
christianbuon Apr 7, 2025
3fb1840
test: now we capture threads info using the current thread
christianbuon Apr 7, 2025
f0c48d7
refactor(FramesStrategy): set truncateTraceChain with default visibil…
christianbuon Apr 12, 2025
c3e547b
refactor(Group): set property as type TraceChain and add getter
christianbuon Apr 12, 2025
eb0b6e1
feat(RollbarThreadStrategy): add truncation strategy for RollbarThread
christianbuon Apr 12, 2025
a757a2c
fix: lint
christianbuon Apr 12, 2025
eef19c6
fix: lint
christianbuon Apr 12, 2025
4e1fce9
fix: lint
christianbuon Apr 12, 2025
6082a70
fix(RollbarThreadStrategy): lint
christianbuon Apr 12, 2025
91ace43
feat: Add strategy for Telemetry events
christianbuon Apr 12, 2025
5a8bc02
feat: Add is_main field
christianbuon Apr 14, 2025
71a6955
refactor: replace Thread by RollbarThread in ThrowableWrapper
christianbuon May 12, 2025
bdfab2f
CI: bump ubuntu image to 22.04
christianbuon May 12, 2025
9eb1e67
fix: lint
christianbuon May 12, 2025
7c096eb
fix: update revapi.yml replacing getThread with getRollbarThread
christianbuon May 12, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ on:
jobs:
validation:
name: Gradle wrapper validation
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: gradle/actions/wrapper-validation@v3

build:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
name: Build with Java ${{ matrix.java }}
needs: [ validation ]
strategy:
Expand Down Expand Up @@ -71,7 +71,7 @@ jobs:
**/build/reports/*

release:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
name: Release
# It would be nice to run this as part of the build job, since it would be
# faster and have less duplicated Yaml, it would not be possible to check
Expand Down
12 changes: 12 additions & 0 deletions .palantir/revapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,15 @@ acceptedBreaks:
- code: "java.method.addedToInterface"
new: "method int com.rollbar.notifier.config.CommonConfig::maximumTelemetryData()"
justification: "This is going to be added in a major version"
"2.1.0":
com.rollbar:rollbar-java:
- code: "java.method.addedToInterface"
new: "method java.util.Map<java.lang.Thread, java.lang.StackTraceElement[]> com.rollbar.notifier.wrapper.ThrowableWrapper::getAllStackTraces()"
justification: "This is a binary compatible change, which could only break custom\
\ implementations of our config interfaces, but those interfaces are not meant\
\ to be implemented by users"
- code: "java.method.addedToInterface"
new: "method com.rollbar.api.payload.data.body.RollbarThread com.rollbar.notifier.wrapper.ThrowableWrapper::getRollbarThread()"
justification: "This is a binary compatible change, which could only break custom\
\ implementations of our config interfaces, but those interfaces are not meant\
\ to be implemented by users"
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,12 @@ public Map<String, Object> asJson() {

@Override
public TelemetryEvent truncateStrings(int maxLength) {
Map<String, String> truncatedMap = new HashMap<>();
for (Map.Entry<String, String> entry : body.entrySet()) {
String truncatedValue = TruncationHelper.truncateString(entry.getValue(), maxLength);
truncatedMap.put(entry.getKey(), truncatedValue);
}
return new TelemetryEvent(
this.type,
this.level,
this.timestamp,
this.source,
truncatedMap
TruncationHelper.truncateStringsInStringMap(body, maxLength)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.rollbar.api.json.JsonSerializable;
import com.rollbar.api.payload.data.TelemetryEvent;
import com.rollbar.api.truncation.StringTruncatable;
import com.rollbar.api.truncation.TruncationHelper;

import java.util.HashMap;
import java.util.List;
Expand All @@ -19,19 +20,41 @@ public class Body implements JsonSerializable, StringTruncatable<Body> {

private final List<TelemetryEvent> telemetryEvents;

private final List<RollbarThread> rollbarThreads;

private Body(Builder builder) {
this.bodyContent = builder.bodyContent;
this.telemetryEvents = builder.telemetryEvents;
this.rollbarThreads = builder.rollbarThreads;
}

/**
* Getter.
*
* @return the contents.
*/
public BodyContent getContents() {
return bodyContent;
}

/**
* Getter.
*
* @return the rollbar threads.
*/
public List<RollbarThread> getRollbarThreads() {
return rollbarThreads;
}

/**
* Getter.
*
* @return the list of Telemetry events.
*/
public List<TelemetryEvent> getTelemetryEvents() {
return telemetryEvents;
}

@Override
public Object asJson() {
HashMap<String, Object> values = new HashMap<>();
Expand All @@ -44,15 +67,21 @@ public Object asJson() {
values.put("telemetry", telemetryEvents);
}

if (rollbarThreads != null) {
values.put("threads", rollbarThreads);
}

return values;
}

@Override
public Body truncateStrings(int maxSize) {
if (bodyContent != null) {
return new Body.Builder(this)
.bodyContent(bodyContent.truncateStrings(maxSize))
.build();
.bodyContent(bodyContent.truncateStrings(maxSize))
.telemetryEvents(TruncationHelper.truncate(telemetryEvents, maxSize))
.rollbarThreads(TruncationHelper.truncate(rollbarThreads, maxSize))
.build();
} else {
return this;
}
Expand All @@ -70,20 +99,22 @@ public boolean equals(Object o) {

Body body = (Body) o;
return Objects.equals(bodyContent, body.bodyContent)
&& Objects.equals(telemetryEvents, body.telemetryEvents);
&& Objects.equals(telemetryEvents, body.telemetryEvents)
&& Objects.equals(rollbarThreads, body.rollbarThreads);
}

@Override
public int hashCode() {
return Objects.hash(bodyContent, telemetryEvents);
return Objects.hash(bodyContent, telemetryEvents, rollbarThreads);
}

@Override
public String toString() {
return "Body{"
+ "bodyContent=" + bodyContent
+ ", telemetry=" + telemetryEvents
+ '}';
+ "bodyContent=" + bodyContent
+ ", telemetry=" + telemetryEvents
+ ", threads=" + rollbarThreads
+ '}';
}

/**
Expand All @@ -95,6 +126,8 @@ public static final class Builder {

private List<TelemetryEvent> telemetryEvents;

private List<RollbarThread> rollbarThreads;

/**
* Constructor.
*/
Expand All @@ -108,8 +141,9 @@ public Builder() {
* @param body the {@link Body body} to initialize a new builder instance.
*/
public Builder(Body body) {
this.bodyContent = body.bodyContent;
this.telemetryEvents = body.telemetryEvents;
bodyContent = body.bodyContent;
telemetryEvents = body.telemetryEvents;
rollbarThreads = body.rollbarThreads;
}

/**
Expand All @@ -135,6 +169,17 @@ public Builder telemetryEvents(List<TelemetryEvent> telemetryEvents) {
return this;
}

/**
* Information from threads.
*
* @param rollbarThreads a list of threads;
* @return the builder instance.
*/
public Builder rollbarThreads(List<RollbarThread> rollbarThreads) {
this.rollbarThreads = rollbarThreads;
return this;
}

/**
* Builds the {@link Body body}.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.rollbar.api.payload.data.body;

import com.rollbar.api.json.JsonSerializable;
import com.rollbar.api.truncation.StringTruncatable;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Objects;

/**
* This represent a Group of trace chains in a Thread.
* In Java we only send 1 TraceChain per Group, in other languages like Python (ExceptionGroup) or
* JS (AggregatorError), it may be more TraceChains per group.
*/
public class Group implements JsonSerializable, StringTruncatable<Group> {
private final TraceChain traceChain;

public Group(TraceChain traceChain) {
this.traceChain = traceChain;
}

/**
* Getter.
*
* @return the trace chain.
*/
public TraceChain getTraceChain() {
return traceChain;
}

@Override
public Object asJson() {
HashMap<String, Object> values = new HashMap<>();
values.put("trace_chain", traceChain);
ArrayList<HashMap<String, Object>> traceChains = new ArrayList<>();
traceChains.add(values);
return traceChains;
}

@Override
public Group truncateStrings(int maxLength) {
return new Group(traceChain.truncateStrings(maxLength));
}

@Override
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) {
return false;
}
Group group = (Group) o;
return Objects.equals(traceChain, group.traceChain);
}

@Override
public int hashCode() {
return Objects.hashCode(traceChain);
}

@Override
public String toString() {
return "Group{traceChain=" + traceChain + '}';
}
}
Loading