DeploymentMetaData { static void reloadServiceName() { ENV_SERVICE_NAME = getServiceNameFromEnv(); ENV_BUILD_STAMP = getBuildStampFromEnv(); INSTANCE = new DeploymentMetaData(ENV_SERVICE_NAME, ENV_BUILD_STAMP); } DeploymentMetaData(String serviceName, String buildStamp); String getServiceName(); void setServiceName(String serviceName); String getBuildStamp(); void setBuildStamp(String buildStamp); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }
@Test public void testServiceNameIsAddedToRootNode() { System.setProperty(PropertyUtil.OPENSHIFT_BUILD_NAME, "vertx-opentracing-1"); System.setProperty(PropertyUtil.OPENSHIFT_BUILD_NAMESPACE, "myproject"); DeploymentMetaData.reloadServiceName(); APMTracerTest.TestTraceRecorder reporter = new APMTracerTest.TestTraceRecorder(); Tracer tracer = new APMTracer(reporter, Sampler.ALWAYS_SAMPLE); Span span = tracer.buildSpan("NoReferences") .start(); span.finish(); assertEquals(1, reporter.getTraces().size()); Trace trace = reporter.getTraces().get(0); Node rootNode = trace.getNodes().get(0); assertTrue(rootNode.hasProperty(Constants.PROP_SERVICE_NAME)); Optional<Property> serviceNameProperty = rootNode.getProperties(Constants.PROP_SERVICE_NAME).stream().findFirst(); assertTrue(serviceNameProperty.isPresent()); assertEquals("myproject.vertx-opentracing", serviceNameProperty.get().getValue()); Optional<Property> buildStampProperty = rootNode.getProperties(Constants.PROP_BUILD_STAMP).stream().findFirst(); assertTrue(buildStampProperty.isPresent()); assertEquals("myproject.vertx-opentracing-1", buildStampProperty.get().getValue()); System.getProperties().remove(PropertyUtil.OPENSHIFT_BUILD_NAME); System.getProperties().remove(PropertyUtil.OPENSHIFT_BUILD_NAMESPACE); }
@Test public void testCustomServiceNameIsAddedToRootNode() { System.setProperty(PropertyUtil.OPENSHIFT_BUILD_NAME, "vertx-opentracing-1"); System.setProperty(PropertyUtil.OPENSHIFT_BUILD_NAMESPACE, "myproject"); DeploymentMetaData.reloadServiceName(); APMTracerTest.TestTraceRecorder reporter = new APMTracerTest.TestTraceRecorder(); Tracer tracer = new APMTracer(reporter, Sampler.ALWAYS_SAMPLE, new DeploymentMetaData("mycustomapp", "mycustomapp-1")); Span span = tracer.buildSpan("NoReferences") .start(); span.finish(); assertEquals(1, reporter.getTraces().size()); Trace trace = reporter.getTraces().get(0); Node rootNode = trace.getNodes().get(0); assertTrue(rootNode.hasProperty(Constants.PROP_SERVICE_NAME)); Optional<Property> serviceNameProperty = rootNode.getProperties(Constants.PROP_SERVICE_NAME).stream().findFirst(); assertTrue(serviceNameProperty.isPresent()); assertEquals("mycustomapp", serviceNameProperty.get().getValue()); Optional<Property> buildStampProperty = rootNode.getProperties(Constants.PROP_BUILD_STAMP).stream().findFirst(); assertTrue(buildStampProperty.isPresent()); assertEquals("mycustomapp-1", buildStampProperty.get().getValue()); System.getProperties().remove(PropertyUtil.OPENSHIFT_BUILD_NAME); System.getProperties().remove(PropertyUtil.OPENSHIFT_BUILD_NAMESPACE); }