@@ -40,23 +40,36 @@ class ExtensionMetricWriter extends MetricWriter{
4040 private StatsDClient client ;
4141
4242 public ExtensionMetricWriter () {
43- this .client = new NonBlockingStatsDClientBuilder ()
44- .prefix ("" )
45- .hostname ("127.0.0.1" )
46- .port (8125 )
47- .build ();
43+ try {
44+ this .client = new NonBlockingStatsDClientBuilder ()
45+ .prefix ("" )
46+ .hostname ("127.0.0.1" )
47+ .port (8125 )
48+ .enableTelemetry (false )
49+ .telemetryFlushInterval (0 )
50+ .build ();
51+ } catch (Exception e ) {
52+ DDLogger .getLoggerImpl ().error ("Could not create StatsDClient " + e .getMessage ());
53+ this .client = null ;
54+ }
4855 }
4956
57+
58+
5059 @ Override
5160 public void write (CustomMetric cm ){
52- StringBuilder tagsSb = new StringBuilder ();
53- if (cm .getTags () != null ) {
54- cm .getTags ().forEach ((k , val ) ->
55- tagsSb .append (k .toLowerCase ())
56- .append (":" )
57- .append (val .toString ().toLowerCase ()));
61+ if (null != client ) {
62+ StringBuilder tagsSb = new StringBuilder ();
63+ if (cm .getTags () != null ) {
64+ cm .getTags ().forEach ((k , val ) ->
65+ tagsSb .append (k .toLowerCase ())
66+ .append (":" )
67+ .append (val .toString ().toLowerCase ()));
68+ }
69+ client .distribution (cm .getName (), cm .getValue (), tagsSb .toString ());
70+ } else {
71+ DDLogger .getLoggerImpl ().error ("Could not write the metric because the client is null" );
5872 }
59- client .distribution (cm .getName (), cm .getValue (), tagsSb .toString ());
6073 }
6174
6275 @ Override
0 commit comments