forked from Azure/azure-sdk-for-java
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add telemetry field truncation (Azure#26880)
- Loading branch information
Showing
30 changed files
with
1,596 additions
and
919 deletions.
There are no files selected for viewing
276 changes: 122 additions & 154 deletions
276
...ter/src/main/java/com/azure/monitor/opentelemetry/exporter/AzureMonitorTraceExporter.java
Large diffs are not rendered by default.
Oops, something went wrong.
114 changes: 0 additions & 114 deletions
114
...ter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/Exceptions.java
This file was deleted.
Oops, something went wrong.
126 changes: 0 additions & 126 deletions
126
...rter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/UrlParser.java
This file was deleted.
Oops, something went wrong.
75 changes: 75 additions & 0 deletions
75
...zure/monitor/opentelemetry/exporter/implementation/builders/AbstractTelemetryBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
// Code generated by Microsoft (R) AutoRest Code Generator. | ||
|
||
package com.azure.monitor.opentelemetry.exporter.implementation.builders; | ||
|
||
import com.azure.monitor.opentelemetry.exporter.implementation.models.MonitorBase; | ||
import com.azure.monitor.opentelemetry.exporter.implementation.models.MonitorDomain; | ||
import com.azure.monitor.opentelemetry.exporter.implementation.models.TelemetryItem; | ||
|
||
import java.time.OffsetDateTime; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public abstract class AbstractTelemetryBuilder { | ||
|
||
private static final int MAX_PROPERTY_KEY_LENGTH = 150; | ||
private static final int MAX_PROPERTY_VALUE_LENGTH = 8192; | ||
|
||
protected static final int MAX_MEASUREMENT_KEY_LENGTH = 150; | ||
|
||
protected static final int MAX_NAME_LENGTH = 1024; | ||
protected static final int MAX_ID_LENGTH = 512; | ||
|
||
private final TelemetryItem telemetryItem; | ||
|
||
protected AbstractTelemetryBuilder(MonitorDomain data, String telemetryName, String baseType) { | ||
|
||
telemetryItem = new TelemetryItem(); | ||
telemetryItem.setVersion(1); | ||
telemetryItem.setName(telemetryName); | ||
|
||
data.setVersion(2); | ||
|
||
MonitorBase monitorBase = new MonitorBase(); | ||
telemetryItem.setData(monitorBase); | ||
monitorBase.setBaseType(baseType); | ||
monitorBase.setBaseData(data); | ||
} | ||
|
||
public void setTime(OffsetDateTime time) { | ||
telemetryItem.setTime(time); | ||
} | ||
|
||
public void setSampleRate(float sampleRate) { | ||
telemetryItem.setSampleRate(sampleRate); | ||
} | ||
|
||
public void setInstrumentationKey(String instrumentationKey) { | ||
telemetryItem.setInstrumentationKey(instrumentationKey); | ||
} | ||
|
||
public void addTag(String key, String value) { | ||
Map<String, String> tags = telemetryItem.getTags(); | ||
if (tags == null) { | ||
tags = new HashMap<>(); | ||
telemetryItem.setTags(tags); | ||
} | ||
tags.put(key, value); | ||
} | ||
|
||
public void addProperty(String key, String value) { | ||
if (key == null || key.isEmpty() || key.length() > MAX_PROPERTY_KEY_LENGTH || value == null) { | ||
// TODO (trask) log | ||
return; | ||
} | ||
getProperties().put(key, TelemetryTruncation.truncatePropertyValue(value, MAX_PROPERTY_VALUE_LENGTH, key)); | ||
} | ||
|
||
public TelemetryItem build() { | ||
return telemetryItem; | ||
} | ||
|
||
protected abstract Map<String, String> getProperties(); | ||
} |
53 changes: 53 additions & 0 deletions
53
...m/azure/monitor/opentelemetry/exporter/implementation/builders/EventTelemetryBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
// Code generated by Microsoft (R) AutoRest Code Generator. | ||
|
||
package com.azure.monitor.opentelemetry.exporter.implementation.builders; | ||
|
||
import com.azure.monitor.opentelemetry.exporter.implementation.models.TelemetryEventData; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public final class EventTelemetryBuilder extends AbstractTelemetryBuilder { | ||
|
||
private static final int MAX_EVENT_NAME_LENGTH = 512; | ||
|
||
private final TelemetryEventData data; | ||
|
||
public static EventTelemetryBuilder create() { | ||
return new EventTelemetryBuilder(new TelemetryEventData()); | ||
} | ||
|
||
private EventTelemetryBuilder(TelemetryEventData data) { | ||
super(data, "Event", "EventData"); | ||
this.data = data; | ||
} | ||
|
||
public void setName(String name) { | ||
data.setName(TelemetryTruncation.truncateTelemetry(name, MAX_EVENT_NAME_LENGTH, "Event.name")); | ||
} | ||
|
||
public void addMeasurement(String key, Double value) { | ||
if (key == null || key.isEmpty() || key.length() > MAX_MEASUREMENT_KEY_LENGTH) { | ||
// TODO (trask) log | ||
return; | ||
} | ||
Map<String, Double> measurements = data.getMeasurements(); | ||
if (measurements == null) { | ||
measurements = new HashMap<>(); | ||
data.setMeasurements(measurements); | ||
} | ||
measurements.put(key, value); | ||
} | ||
|
||
@Override | ||
protected Map<String, String> getProperties() { | ||
Map<String, String> properties = data.getProperties(); | ||
if (properties == null) { | ||
properties = new HashMap<>(); | ||
data.setProperties(properties); | ||
} | ||
return properties; | ||
} | ||
} |
Oops, something went wrong.