com.newrelic.telemetry.logs.json.LogJsonCommonBlockWriter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of telemetry-core Show documentation
Show all versions of telemetry-core Show documentation
Used to send telemetry data to New Relic
/*
* Copyright 2020 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
package com.newrelic.telemetry.logs.json;
import com.google.gson.stream.JsonWriter;
import com.newrelic.telemetry.json.AttributesJson;
import com.newrelic.telemetry.logs.LogBatch;
import java.io.IOException;
public class LogJsonCommonBlockWriter {
private final AttributesJson attributesJson;
public LogJsonCommonBlockWriter(AttributesJson attributesJson) {
this.attributesJson = attributesJson;
}
public void appendCommonJson(LogBatch batch, JsonWriter jsonWriter) {
if (!batch.hasCommonAttributes()) {
return;
}
try {
jsonWriter.name("common");
jsonWriter.beginObject();
jsonWriter.name("attributes");
jsonWriter.jsonValue(attributesJson.toJson(batch.getCommonAttributes().asMap()));
jsonWriter.endObject();
} catch (IOException e) {
throw new RuntimeException("Failed to create log common block json", e);
}
}
@Override
public String toString() {
return "LogJsonCommonBlockWriter{" + "attributesJson=" + attributesJson + '}';
}
}