Skip to content

Commit c36ead7

Browse files
Merge pull request #218 from KarstenSchnitter/release-4
Port minor changes to release-4
2 parents 87bf1d2 + e1027ab commit c36ead7

File tree

6 files changed

+37
-50
lines changed

6 files changed

+37
-50
lines changed

.reuse/dep5

Lines changed: 0 additions & 30 deletions
This file was deleted.

REUSE.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version = 1
2+
SPDX-PackageName = "CF Java Logging Support"
3+
SPDX-PackageSupplier = "<k.schnitter@sap.com>"
4+
SPDX-PackageDownloadLocation = "https://github.com/SAP/cf-java-logging-support"
5+
SPDX-PackageComment = "The code in this project may include calls to APIs (“API Calls”) of\n SAP or third-party products or services developed outside of this project\n (“External Products”).\n “APIs” means application programming interfaces, as well as their respective\n specifications and implementing code that allows software to communicate with\n other software.\n API Calls to External Products are not licensed under the open source license\n that governs this project. The use of such API Calls and related External\n Products are subject to applicable additional agreements with the relevant\n provider of the External Products. In no event shall the open source license\n that governs this project grant any rights in or to any External Products,or\n alter, expand or supersede any terms of the applicable additional agreements.\n If you have a valid license agreement with SAP for the use of a particular SAP\n External Product, then you may make use of any API Calls included in this\n project’s code for that SAP External Product, subject to the terms of such\n license agreement. If you do not have a valid license agreement for the use of\n a particular SAP External Product, then you may only make use of any API Calls\n in this project for that SAP External Product for your internal, non-productive\n and non-commercial test and evaluation of such API Calls. Nothing herein grants\n you any rights to use or access any SAP External Product, or provide any third\n parties the right to use of access any SAP External Product, through API Calls."
6+
7+
[[annotations]]
8+
path = "**"
9+
precedence = "aggregate"
10+
SPDX-FileCopyrightText = "2020 SAP SE or an SAP affiliate company and CF Java Logging Support contributors"
11+
SPDX-License-Identifier = "Apache-2.0"

cf-java-logging-support-core/beats/app-logs/docs/fields.asciidoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -498,16 +498,16 @@ type: object
498498

499499
example: "#cf": {
500500
"string": [
501-
{"l":"some_label", "v":"some_value", "i": 0},
502-
{"l":"other_label", "v":"other_value", "i": 1}
501+
{"k":"some_key", "v":"some_value", "i": 0},
502+
{"k":"other_key", "v":"other_value", "i": 1}
503503
]
504504
}
505505

506506

507507
required: False
508508

509509
An object containing collections of non-standard fields.
510-
The field "string" contains custom fields with label "l", value "v" and an index "i".
510+
The field "string" contains custom fields with key "k", value "v" and an index "i".
511511
The index can be used for field order during parsing.
512512

513513
NOTE: As this is "custom" there are no predefined fields here!

cf-java-logging-support-core/beats/app-logs/etc/fields.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,13 +348,13 @@ app-logs:
348348
example: |
349349
"#cf": {
350350
"string": [
351-
{"l":"some_label", "v":"some_value", "i": 0},
352-
{"l":"other_label", "v":"other_value", "i": 1}
351+
{"k":"some_key", "v":"some_value", "i": 0},
352+
{"k":"other_key", "v":"other_value", "i": 1}
353353
]
354354
}
355355
description: |
356356
An object containing collections of non-standard fields.
357-
The field "string" contains custom fields with label "l", value "v" and an index "i".
357+
The field "string" contains custom fields with key "k", value "v" and an index "i".
358358
The index can be used for field order during parsing.
359359
360360
NOTE: As this is "custom" there are no predefined fields here!

cf-java-logging-support-opentelemetry-agent-extension/src/main/java/com/sap/hcf/cf/logging/opentelemetry/agent/ext/exporter/DynatraceMetricsExporterProvider.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import io.opentelemetry.sdk.common.export.RetryPolicy;
1010
import io.opentelemetry.sdk.metrics.Aggregation;
1111
import io.opentelemetry.sdk.metrics.InstrumentType;
12+
import io.opentelemetry.sdk.metrics.data.AggregationTemporality;
1213
import io.opentelemetry.sdk.metrics.export.AggregationTemporalitySelector;
1314
import io.opentelemetry.sdk.metrics.export.DefaultAggregationSelector;
1415
import io.opentelemetry.sdk.metrics.export.MetricExporter;
@@ -27,6 +28,7 @@ public class DynatraceMetricsExporterProvider implements ConfigurableMetricExpor
2728
public static final String CRED_DYNATRACE_APIURL = "apiurl";
2829
public static final String DT_APIURL_METRICS_SUFFIX = "/v2/otlp/v1/metrics";
2930
private static final Logger LOG = Logger.getLogger(DynatraceMetricsExporterProvider.class.getName());
31+
private static final AggregationTemporalitySelector ALWAYS_DELTA = instrumentType -> AggregationTemporality.DELTA;
3032
private final Function<ConfigProperties, CfService> serviceProvider;
3133

3234
public DynatraceMetricsExporterProvider() {
@@ -50,7 +52,7 @@ private static Duration getTimeOut(ConfigProperties config) {
5052
private static AggregationTemporalitySelector getAggregationTemporalitySelector(ConfigProperties config) {
5153
String temporalityStr = config.getString("otel.exporter.dynatrace.metrics.temporality.preference");
5254
if (temporalityStr == null) {
53-
return AggregationTemporalitySelector.deltaPreferred();
55+
return ALWAYS_DELTA;
5456
}
5557
AggregationTemporalitySelector temporalitySelector;
5658
switch (temporalityStr.toLowerCase(Locale.ROOT)) {
@@ -60,6 +62,8 @@ private static AggregationTemporalitySelector getAggregationTemporalitySelector(
6062
return AggregationTemporalitySelector.deltaPreferred();
6163
case "lowmemory":
6264
return AggregationTemporalitySelector.lowMemory();
65+
case "always_delta":
66+
return ALWAYS_DELTA;
6367
default:
6468
throw new ConfigurationException("Unrecognized aggregation temporality: " + temporalityStr);
6569
}

cf-java-logging-support-servlet/src/main/java/com/sap/hcp/cf/logging/servlet/filter/CorrelationIdFilter.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@
1010
import org.slf4j.LoggerFactory;
1111

1212
import java.util.UUID;
13-
import java.util.function.Predicate;
1413

1514
import static com.sap.hcp.cf.logging.common.customfields.CustomField.customField;
1615
import static com.sap.hcp.cf.logging.common.request.HttpHeaders.W3C_TRACEPARENT;
17-
import static java.util.Optional.ofNullable;
1816

1917
/**
2018
* The {@link CorrelationIdFilter} extracts a correlation id according to {@link HttpHeaders#CORRELATION_ID}. It will
@@ -24,8 +22,8 @@
2422
public class CorrelationIdFilter extends AbstractLoggingFilter {
2523

2624
private static final Logger LOG = LoggerFactory.getLogger(CorrelationIdFilter.class);
27-
private HttpHeader correlationHeader;
28-
private HttpHeader traceparentHeader;
25+
private final HttpHeader correlationHeader;
26+
private final HttpHeader traceparentHeader;
2927

3028
public CorrelationIdFilter() {
3129
this(HttpHeaders.CORRELATION_ID);
@@ -62,22 +60,26 @@ private String determineCorrelationId(HttpServletRequest request) {
6260
return correlationId;
6361
}
6462

65-
private boolean isBlankOrDefault(String value) {
63+
private static boolean isBlankOrDefault(String value) {
6664
return value == null || value.isEmpty() || value.equals(Defaults.UNKNOWN);
6765
}
6866

6967
private String getCorrelationIdFromTraceparent(HttpServletRequest request) {
7068
String traceparent = HttpHeaderUtilities.getHeaderValue(request, traceparentHeader);
71-
return ofNullable(traceparent).filter(not(this::isBlankOrDefault)).map(this::parseTraceparent).orElse(null);
69+
return isBlankOrDefault(traceparent) ? null : parseTraceparent(traceparent);
7270
}
7371

74-
private <T> Predicate<T> not(Predicate<T> p) {
75-
return p.negate();
76-
}
77-
78-
private String parseTraceparent(String value) {
79-
String[] tokens = value.split("-");
80-
return tokens.length >= 2 ? tokens[1] : null;
72+
private static String parseTraceparent(String value) {
73+
int idx1 = value.indexOf('-');
74+
if (idx1 != -1) {
75+
++idx1;
76+
int idx2 = value.indexOf('-', idx1);
77+
if (idx2 != -1) {
78+
// return string between first and second '-'.
79+
return value.substring(idx1, idx2);
80+
}
81+
}
82+
return null;
8183
}
8284

8385
private void addCorrelationIdHeader(HttpServletResponse response, String correlationId) {

0 commit comments

Comments
 (0)