Skip to content

Commit 99355a3

Browse files
paranoid exception handling when setting profiling thread context (#7903)
1 parent 15e5861 commit 99355a3

File tree

1 file changed

+17
-5
lines changed
  • dd-java-agent/agent-profiling/profiling-ddprof/src/main/java/com/datadog/profiling/ddprof

1 file changed

+17
-5
lines changed

dd-java-agent/agent-profiling/profiling-ddprof/src/main/java/com/datadog/profiling/ddprof/DatadogProfiler.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ public void setSpanContext(long spanId, long rootSpanId) {
329329
debugLogging(rootSpanId);
330330
try {
331331
profiler.setContext(spanId, rootSpanId);
332-
} catch (IllegalStateException e) {
332+
} catch (Throwable e) {
333333
log.debug("Failed to clear context", e);
334334
}
335335
}
@@ -338,22 +338,30 @@ public void clearSpanContext() {
338338
debugLogging(0L);
339339
try {
340340
profiler.setContext(0L, 0L);
341-
} catch (IllegalStateException e) {
341+
} catch (Throwable e) {
342342
log.debug("Failed to set context", e);
343343
}
344344
}
345345

346346
public boolean setContextValue(int offset, int encoding) {
347347
if (contextSetter != null && offset >= 0) {
348-
return contextSetter.setContextValue(offset, encoding);
348+
try {
349+
return contextSetter.setContextValue(offset, encoding);
350+
} catch (Throwable e) {
351+
log.debug("Failed to set context", e);
352+
}
349353
}
350354
return false;
351355
}
352356

353357
public boolean setContextValue(int offset, CharSequence value) {
354358
if (contextSetter != null && offset >= 0) {
355359
int encoding = encode(value);
356-
return contextSetter.setContextValue(offset, encoding);
360+
try {
361+
return contextSetter.setContextValue(offset, encoding);
362+
} catch (Throwable e) {
363+
log.debug("Failed to set context", e);
364+
}
357365
}
358366
return false;
359367
}
@@ -374,7 +382,11 @@ public boolean clearContextValue(String attribute) {
374382

375383
public boolean clearContextValue(int offset) {
376384
if (contextSetter != null && offset >= 0) {
377-
return contextSetter.clearContextValue(offset);
385+
try {
386+
return contextSetter.clearContextValue(offset);
387+
} catch (Throwable t) {
388+
log.debug("Failed to clear context", t);
389+
}
378390
}
379391
return false;
380392
}

0 commit comments

Comments
 (0)