Skip to content

Add SentryAttribute.flattened #4417

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

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

import io.sentry.ISpan;
import io.sentry.Sentry;
import io.sentry.SentryAttribute;
import io.sentry.SentryAttributes;
import io.sentry.SentryLogLevel;
import io.sentry.logger.SentryLogParameters;
import java.awt.Point;
import java.util.Collections;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
Expand Down Expand Up @@ -29,6 +35,29 @@ Person person(@PathVariable Long id) {
Sentry.logger().warn("warn Sentry logging");
Sentry.logger().error("error Sentry logging");
Sentry.logger().info("hello %s %s", "there", "world!");
Sentry.logger()
.log(
SentryLogLevel.ERROR,
SentryLogParameters.create(
null,
SentryAttributes.fromMap(Collections.singletonMap("extra-attr", "attr-value"))),
"hello %s %s",
"there",
"world!");
Sentry.logger()
.log(
SentryLogLevel.ERROR,
SentryLogParameters.create(
SentryAttributes.of(
SentryAttribute.booleanAttribute("boolattr", true),
SentryAttribute.integerAttribute("intattr", 17),
SentryAttribute.doubleAttribute("doubleattr", 0.8),
SentryAttribute.stringAttribute("strattr", "strval"),
SentryAttribute.named("namedAttr", new Point(10, 20)),
SentryAttribute.flattened("flattenedAttr", new Point(10, 20)))),
"hello %s %s",
"there",
"world!");
LOGGER.error("Trying person with id={}", id, new RuntimeException("error while loading"));
throw new IllegalArgumentException("Something went wrong [id=" + id + "]");
} finally {
Expand Down
45 changes: 45 additions & 0 deletions sentry/api/sentry.api
Original file line number Diff line number Diff line change
Expand Up @@ -1250,6 +1250,7 @@ public final class io/sentry/JsonObjectWriter : io/sentry/ObjectWriter {
}

public final class io/sentry/JsonReflectionObjectSerializer {
public fun <init> (I)V
public fun serialize (Ljava/lang/Object;Lio/sentry/ILogger;)Ljava/lang/Object;
public fun serializeObject (Ljava/lang/Object;Lio/sentry/ILogger;)Ljava/util/Map;
}
Expand Down Expand Up @@ -2658,6 +2659,36 @@ public final class io/sentry/SentryAppStartProfilingOptions$JsonKeys {
public fun <init> ()V
}

public final class io/sentry/SentryAttribute {
public static fun booleanAttribute (Ljava/lang/String;Ljava/lang/Boolean;)Lio/sentry/SentryAttribute;
public static fun doubleAttribute (Ljava/lang/String;Ljava/lang/Double;)Lio/sentry/SentryAttribute;
public static fun flattened (Ljava/lang/String;Ljava/lang/Object;)Lio/sentry/SentryAttribute;
public fun getFlattenDepth ()I
public fun getName ()Ljava/lang/String;
public fun getType ()Lio/sentry/SentryAttributeType;
public fun getValue ()Ljava/lang/Object;
public static fun integerAttribute (Ljava/lang/String;Ljava/lang/Integer;)Lio/sentry/SentryAttribute;
public static fun named (Ljava/lang/String;Ljava/lang/Object;)Lio/sentry/SentryAttribute;
public static fun stringAttribute (Ljava/lang/String;Ljava/lang/String;)Lio/sentry/SentryAttribute;
}

public final class io/sentry/SentryAttributeType : java/lang/Enum {
public static final field BOOLEAN Lio/sentry/SentryAttributeType;
public static final field DOUBLE Lio/sentry/SentryAttributeType;
public static final field INTEGER Lio/sentry/SentryAttributeType;
public static final field STRING Lio/sentry/SentryAttributeType;
public fun apiName ()Ljava/lang/String;
public static fun valueOf (Ljava/lang/String;)Lio/sentry/SentryAttributeType;
public static fun values ()[Lio/sentry/SentryAttributeType;
}

public final class io/sentry/SentryAttributes {
public fun add (Lio/sentry/SentryAttribute;)V
public static fun fromMap (Ljava/util/Map;)Lio/sentry/SentryAttributes;
public fun getAttributes ()Ljava/util/Map;
public static fun of ([Lio/sentry/SentryAttribute;)Lio/sentry/SentryAttributes;
}

public final class io/sentry/SentryAutoDateProvider : io/sentry/SentryDateProvider {
public fun <init> ()V
public fun now ()Lio/sentry/SentryDate;
Expand Down Expand Up @@ -3077,6 +3108,7 @@ public final class io/sentry/SentryLogEvent$JsonKeys {
}

public final class io/sentry/SentryLogEventAttributeValue : io/sentry/JsonSerializable, io/sentry/JsonUnknown {
public fun <init> (Lio/sentry/SentryAttributeType;Ljava/lang/Object;)V
public fun <init> (Ljava/lang/String;Ljava/lang/Object;)V
public fun getType ()Ljava/lang/String;
public fun getUnknown ()Ljava/util/Map;
Expand Down Expand Up @@ -4711,6 +4743,7 @@ public abstract interface class io/sentry/logger/ILoggerApi {
public abstract fun fatal (Ljava/lang/String;[Ljava/lang/Object;)V
public abstract fun info (Ljava/lang/String;[Ljava/lang/Object;)V
public abstract fun log (Lio/sentry/SentryLogLevel;Lio/sentry/SentryDate;Ljava/lang/String;[Ljava/lang/Object;)V
public abstract fun log (Lio/sentry/SentryLogLevel;Lio/sentry/logger/SentryLogParameters;Ljava/lang/String;[Ljava/lang/Object;)V
public abstract fun log (Lio/sentry/SentryLogLevel;Ljava/lang/String;[Ljava/lang/Object;)V
public abstract fun trace (Ljava/lang/String;[Ljava/lang/Object;)V
public abstract fun warn (Ljava/lang/String;[Ljava/lang/Object;)V
Expand All @@ -4728,6 +4761,7 @@ public final class io/sentry/logger/LoggerApi : io/sentry/logger/ILoggerApi {
public fun fatal (Ljava/lang/String;[Ljava/lang/Object;)V
public fun info (Ljava/lang/String;[Ljava/lang/Object;)V
public fun log (Lio/sentry/SentryLogLevel;Lio/sentry/SentryDate;Ljava/lang/String;[Ljava/lang/Object;)V
public fun log (Lio/sentry/SentryLogLevel;Lio/sentry/logger/SentryLogParameters;Ljava/lang/String;[Ljava/lang/Object;)V
public fun log (Lio/sentry/SentryLogLevel;Ljava/lang/String;[Ljava/lang/Object;)V
public fun trace (Ljava/lang/String;[Ljava/lang/Object;)V
public fun warn (Ljava/lang/String;[Ljava/lang/Object;)V
Expand All @@ -4748,6 +4782,7 @@ public final class io/sentry/logger/NoOpLoggerApi : io/sentry/logger/ILoggerApi
public static fun getInstance ()Lio/sentry/logger/NoOpLoggerApi;
public fun info (Ljava/lang/String;[Ljava/lang/Object;)V
public fun log (Lio/sentry/SentryLogLevel;Lio/sentry/SentryDate;Ljava/lang/String;[Ljava/lang/Object;)V
public fun log (Lio/sentry/SentryLogLevel;Lio/sentry/logger/SentryLogParameters;Ljava/lang/String;[Ljava/lang/Object;)V
public fun log (Lio/sentry/SentryLogLevel;Ljava/lang/String;[Ljava/lang/Object;)V
public fun trace (Ljava/lang/String;[Ljava/lang/Object;)V
public fun warn (Ljava/lang/String;[Ljava/lang/Object;)V
Expand All @@ -4759,6 +4794,16 @@ public final class io/sentry/logger/NoOpLoggerBatchProcessor : io/sentry/logger/
public static fun getInstance ()Lio/sentry/logger/NoOpLoggerBatchProcessor;
}

public final class io/sentry/logger/SentryLogParameters {
public fun <init> ()V
public static fun create (Lio/sentry/SentryAttributes;)Lio/sentry/logger/SentryLogParameters;
public static fun create (Lio/sentry/SentryDate;Lio/sentry/SentryAttributes;)Lio/sentry/logger/SentryLogParameters;
public fun getAttributes ()Lio/sentry/SentryAttributes;
public fun getTimestamp ()Lio/sentry/SentryDate;
public fun setAttributes (Lio/sentry/SentryAttributes;)V
public fun setTimestamp (Lio/sentry/SentryDate;)V
}

public final class io/sentry/opentelemetry/OpenTelemetryUtil {
public fun <init> ()V
public static fun applyIgnoredSpanOrigins (Lio/sentry/SentryOptions;)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public final class JsonReflectionObjectSerializer {
private final Set<Object> visiting = new HashSet<>();
private final int maxDepth;

JsonReflectionObjectSerializer(int maxDepth) {
public JsonReflectionObjectSerializer(int maxDepth) {
this.maxDepth = maxDepth;
}

Expand Down
69 changes: 69 additions & 0 deletions sentry/src/main/java/io/sentry/SentryAttribute.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package io.sentry;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public final class SentryAttribute {

private final @NotNull String name;
private final @Nullable SentryAttributeType type;
private final @Nullable Object value;
private final int flattenDepth;

private SentryAttribute(
final @NotNull String name,
final @Nullable SentryAttributeType type,
final @Nullable Object value,
final int flattenDepth) {
this.name = name;
this.type = type;
this.value = value;
this.flattenDepth = flattenDepth;
}

public @NotNull String getName() {
return name;
}

public @Nullable SentryAttributeType getType() {
return type;
}

public @Nullable Object getValue() {
return value;
}

public int getFlattenDepth() {
return flattenDepth;
}

public static @NotNull SentryAttribute named(
final @NotNull String name, final @Nullable Object value) {
return new SentryAttribute(name, null, value, 0);
}

public static @NotNull SentryAttribute flattened(
final @NotNull String name, final @Nullable Object value) {
return new SentryAttribute(name, null, value, 1);
}

public static @NotNull SentryAttribute booleanAttribute(
final @NotNull String name, final @Nullable Boolean value) {
return new SentryAttribute(name, SentryAttributeType.BOOLEAN, value, 0);
}

public static @NotNull SentryAttribute integerAttribute(
final @NotNull String name, final @Nullable Integer value) {
return new SentryAttribute(name, SentryAttributeType.INTEGER, value, 0);
}

public static @NotNull SentryAttribute doubleAttribute(
final @NotNull String name, final @Nullable Double value) {
return new SentryAttribute(name, SentryAttributeType.DOUBLE, value, 0);
}

public static @NotNull SentryAttribute stringAttribute(
final @NotNull String name, final @Nullable String value) {
return new SentryAttribute(name, SentryAttributeType.STRING, value, 0);
}
}
15 changes: 15 additions & 0 deletions sentry/src/main/java/io/sentry/SentryAttributeType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.sentry;

import java.util.Locale;
import org.jetbrains.annotations.NotNull;

public enum SentryAttributeType {
STRING,
BOOLEAN,
INTEGER,
DOUBLE;

public @NotNull String apiName() {
return name().toLowerCase(Locale.ROOT);
}
}
54 changes: 54 additions & 0 deletions sentry/src/main/java/io/sentry/SentryAttributes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package io.sentry;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public final class SentryAttributes {

private final @NotNull Map<String, SentryAttribute> attributes;

private SentryAttributes(final @NotNull Map<String, SentryAttribute> attributes) {
this.attributes = attributes;
}

public void add(final @Nullable SentryAttribute attribute) {
if (attribute == null) {
return;
}
attributes.put(attribute.getName(), attribute);
}

public @NotNull Map<String, SentryAttribute> getAttributes() {
return attributes;
}

public static @NotNull SentryAttributes of(final @Nullable SentryAttribute... attributes) {
if (attributes == null) {
return new SentryAttributes(new ConcurrentHashMap<>());
}
final @NotNull SentryAttributes sentryAttributes =
new SentryAttributes(new ConcurrentHashMap<>(attributes.length));
for (SentryAttribute attribute : attributes) {
sentryAttributes.add(attribute);
}
return sentryAttributes;
}

public static @NotNull SentryAttributes fromMap(final @Nullable Map<String, Object> attributes) {
if (attributes == null) {
return new SentryAttributes(new ConcurrentHashMap<>());
}
final @NotNull SentryAttributes sentryAttributes =
new SentryAttributes(new ConcurrentHashMap<>(attributes.size()));
for (Map.Entry<String, Object> attribute : attributes.entrySet()) {
final @Nullable String key = attribute.getKey();
if (key != null) {
sentryAttributes.add(SentryAttribute.named(key, attribute.getValue()));
}
}

return sentryAttributes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,16 @@ public final class SentryLogEventAttributeValue implements JsonUnknown, JsonSeri

public SentryLogEventAttributeValue(final @NotNull String type, final @Nullable Object value) {
this.type = type;
this.value = value;
if (value != null && type.equals("string")) {
this.value = value.toString();
} else {
this.value = value;
}
}

public SentryLogEventAttributeValue(
final @NotNull SentryAttributeType type, final @Nullable Object value) {
this(type.apiName(), value);
}

public @NotNull String getType() {
Expand Down
6 changes: 6 additions & 0 deletions sentry/src/main/java/io/sentry/logger/ILoggerApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,10 @@ void log(
@Nullable SentryDate timestamp,
@Nullable String message,
@Nullable Object... args);

void log(
@NotNull SentryLogLevel level,
@NotNull SentryLogParameters params,
@Nullable String message,
@Nullable Object... args);
}
Loading
Loading