MediaWiki master
OtlpSerializer.php
Go to the documentation of this file.
1<?php
2namespace Wikimedia\Telemetry;
3
14 private const TYPE_MAP = [
15 'string' => 'stringValue',
16 'integer' => 'intValue',
17 'boolean' => 'boolValue',
18 'double' => 'doubleValue',
19 'array' => 'arrayValue'
20 ];
21
27 public static function serializeKeyValuePairs( array $keyValuePairs ): array {
28 $serialized = [];
29
30 foreach ( $keyValuePairs as $key => $value ) {
31 $type = gettype( $value );
32
33 if ( isset( self::TYPE_MAP[$type] ) ) {
34 $serialized[] = [
35 'key' => $key,
36 'value' => [ self::TYPE_MAP[$type] => $value ]
37 ];
38 }
39 }
40
41 return $serialized;
42 }
43}
Utility class for serializing data in OTLP JSON format.
static serializeKeyValuePairs(array $keyValuePairs)
Serialize an associative array into the format expected by the OTLP JSON format.