Skip to content

Commit 472e584

Browse files
dougqhdevflow.devflow-routing-intake
andauthored
Add @ForegroundSafe / @BackgroundOnly marker annotations (#12471)
Add @ForegroundSafe / @BackgroundOnly marker annotations Documentation-and-tooling markers declaring whether code is cheap enough for application (foreground) threads or must be confined to a background thread the tracer paces itself. No application to real code yet and no checker -- just the annotation types, following the Strategy/StrategyConsumer marker convention (APMLP-1543). Merge branch 'master' into dougqh/foreground-safe-background-only-annotations Co-authored-by: devflow.devflow-routing-intake <devflow.devflow-routing-intake@kubernetes.us1.ddbuild.io>
1 parent b9dbc3a commit 472e584

2 files changed

Lines changed: 69 additions & 0 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package datadog.trace.api.function;
2+
3+
import java.lang.annotation.Documented;
4+
import java.lang.annotation.ElementType;
5+
import java.lang.annotation.Retention;
6+
import java.lang.annotation.RetentionPolicy;
7+
import java.lang.annotation.Target;
8+
9+
/**
10+
* Marks code that must be confined to a background thread the tracer owns and paces itself -- e.g.
11+
* serialization, stats aggregation, or eviction -- and must never be reached from an application
12+
* thread (the foreground; see {@link ForegroundSafe}), where its cost would become customer-visible
13+
* latency instead.
14+
*
15+
* <p>This is a documentation-and-tooling marker; it changes no behavior. It exists to telegraph the
16+
* constraint to readers and to give a future checker (see {@code APMLP-1645}) something to verify
17+
* -- that no {@code @BackgroundOnly} code is reachable from a foreground call site. The discipline
18+
* it names is <b>not yet enforced</b>; hold to it by hand until the checker lands.
19+
*
20+
* <p>The two markers are <b>not symmetric</b> -- see {@link ForegroundSafe} for why it, not this
21+
* one, is the strictly stronger guarantee.
22+
*
23+
* <p><b>On a type</b> ({@link ElementType#TYPE}): every method of this type is background-only
24+
* unless a method-level {@link ForegroundSafe} widens it.
25+
*
26+
* <p><b>On a method</b> ({@link ElementType#METHOD}): this method specifically is background-only,
27+
* regardless of what the enclosing type declares -- a method-level marker always wins over the
28+
* type-level one.
29+
*/
30+
@Documented
31+
@Retention(RetentionPolicy.SOURCE)
32+
@Target({ElementType.TYPE, ElementType.METHOD})
33+
public @interface BackgroundOnly {}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package datadog.trace.api.function;
2+
3+
import java.lang.annotation.Documented;
4+
import java.lang.annotation.ElementType;
5+
import java.lang.annotation.Retention;
6+
import java.lang.annotation.RetentionPolicy;
7+
import java.lang.annotation.Target;
8+
9+
/**
10+
* Marks code cheap enough to call from an application thread (the foreground) -- the request or
11+
* transaction thread the instrumented application itself is running, where any added cost is
12+
* customer-visible latency, as opposed to a background thread the tracer owns and paces itself (see
13+
* {@link BackgroundOnly}).
14+
*
15+
* <p>This is a documentation-and-tooling marker; it changes no behavior. It exists to telegraph the
16+
* guarantee to readers and to give a future checker (see {@code APMLP-1645}) something to verify --
17+
* that no {@link BackgroundOnly} code is reachable from a foreground call site. The discipline it
18+
* names is <b>not yet enforced</b>; hold to it by hand until the checker lands.
19+
*
20+
* <p>The two markers are <b>not symmetric</b>. {@code @ForegroundSafe} is the strictly stronger
21+
* guarantee: code cheap enough for the foreground is automatically fine to call from a background
22+
* thread too, so a {@code @ForegroundSafe} type or method may be called from either. {@link
23+
* BackgroundOnly} code carries no such guarantee and must never be reached from a foreground call
24+
* site.
25+
*
26+
* <p><b>On a type</b> ({@link ElementType#TYPE}): every method of this type is foreground-safe
27+
* unless a method-level {@link BackgroundOnly} narrows it.
28+
*
29+
* <p><b>On a method</b> ({@link ElementType#METHOD}): this method specifically is foreground-safe,
30+
* regardless of what the enclosing type declares -- a method-level marker always wins over the
31+
* type-level one.
32+
*/
33+
@Documented
34+
@Retention(RetentionPolicy.SOURCE)
35+
@Target({ElementType.TYPE, ElementType.METHOD})
36+
public @interface ForegroundSafe {}

0 commit comments

Comments
 (0)