Giter Site home page Giter Site logo

Comments (9)

avdhut1990 avatar avdhut1990 commented on May 25, 2024 1

Hi @jeanbisutti, thanks for your help. The requirement to capture request payload has been deprioritized. Will reach out when it gets prioritized again.
Closing this ticket for now.
Thanks.

from applicationinsights-java.

jeanbisutti avatar jeanbisutti commented on May 25, 2024

Hi @avdhut1990!

You can use the Restlet instrumentation libraries with the Application Insights Java agent

https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/docs/supported-libraries.md#libraries--frameworks

image

from applicationinsights-java.

avdhut1990 avatar avdhut1990 commented on May 25, 2024

Hi @jeanbisutti, I have added the opentelemetry restlet dependencies in application in addition to the existing auto-instrumentation using app insights agent. Do I need perform any additional steps?

Thanks.

from applicationinsights-java.

jeanbisutti avatar jeanbisutti commented on May 25, 2024

Hi @jeanbisutti, I have added the opentelemetry restlet dependencies in application in addition to the existing auto-instrumentation using app insights agent. Do I need perform any additional steps?

Thanks.

You can have a look at the examples of the test folder, for example for Restlet 2: https://github.com/open-telemetry/opentelemetry-java-instrumentation/tree/main/instrumentation/restlet/restlet-2.0/library/src/test/groovy/io/opentelemetry/instrumentation/restlet/v2_0

from applicationinsights-java.

avdhut1990 avatar avdhut1990 commented on May 25, 2024

Hi @jeanbisutti ,

I have added the RestletTelemetryBuilder and StatusFilter code to the following method as per the example, however still not getting the requests captured in app insights. Do note that the application is already instrumented using app insights java agent and is able to capture traces and dependencies. Only requests are not getting captured.

package com.msci.esg.dataservice.restlet;

import java.io.File;
import java.io.IOException;
import java.util.Properties;
import java.util.logging.Level;

import com.msci.esg.dataservice.collaborators.usermanagement.UserManagementClientFactory;
import com.msci.esg.dataservice.screening.ChangeReportGenerator;
import com.azure.identity.DefaultAzureCredentialBuilder;
import com.azure.security.keyvault.secrets.SecretClientBuilder;
import com.azure.storage.blob.BlobServiceClientBuilder;
import com.msci.esg.dataservice.CollaboratorClient;
import com.msci.esg.dataservice.azure.appconfig.AzureAppConfigInfo;
import com.msci.esg.dataservice.azure.appconfig.AzureAppConfigStorer;
import com.msci.esg.dataservice.azure.storage.AdlsStorage;
import com.msci.esg.dataservice.collaborators.wsdata.WSDataClient;
import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.instrumentation.restlet.v2_0.RestletTelemetry;
import org.apache.commons.lang3.SystemUtils;
import org.restlet.Application;
import org.restlet.Component;
import org.restlet.Restlet;
import org.restlet.Server;
import org.restlet.data.Protocol;
import org.restlet.data.Reference;
import org.restlet.engine.application.StatusFilter;
import org.restlet.resource.Directory;
import org.restlet.routing.Redirector;
import org.restlet.routing.Router;

import com.msci.esg.dataservice.collaborators.capture.CaptureClientFactory;
import com.msci.esg.dataservice.collaborators.princexml.PrinceXMLClientFactory;
import com.msci.esg.dataservice.collaborators.wsdata.WSDataClientFactory;
import com.msci.esg.dataservice.config.ConfigurationManager;
import com.msci.esg.dataservice.config.GlobalConfigCache;
import com.msci.esg.dataservice.types.ESGDataServicesConfig;
import com.msci.esg.dataservice.types.ServerLocation;
import com.msci.esg.dataservice.utils.LogRecorder;
import org.restlet.service.StatusService;


public class ESGDataServiceApplication extends Application {
	private static final LogRecorder auditer; static { auditer = LogRecorder.logger(); }

	private static Component component = null;
	private final String serviceHost;
	private final int servicePort;
	private final boolean omitPort;
	private boolean streamResults;
	public static final String RESTLET_HTTP_HEADERS= "org.restlet.http.headers";
	
	@Override
	public synchronized Restlet createInboundRoot() {
		final Router router = new Router(getContext());
        router.attach("/query", streamResults ? StreamingQueryResource.class : QueryResource.class);
        router.attach("/report", ReportResource.class);
        router.attach("/home", HomeResource.class);
        router.attach("/systemInfo", SystemInfoResource.class);
        router.attach("/post", PostResource.class);
        router.attach("/post/{name}", PostResource.class);
        router.attach("/query/{name}", streamResults ? StreamingPostPageQueryResource.class : PostPageQueryResource.class);
        router.attach("/itemImport", ItemImportResource.class);
        router.attach("/stream", StreamResource.class);

		RestletTelemetry telemetry = RestletTelemetry.builder(GlobalOpenTelemetry.get()).build();
		StatusFilter statusFilter = new StatusFilter(component.getContext(), new StatusService());
		telemetry.newFilter("/query").setNext(statusFilter);
		telemetry.newFilter("/report").setNext(statusFilter);
		telemetry.newFilter("/home").setNext(statusFilter);
		telemetry.newFilter("/systemInfo").setNext(statusFilter);
		telemetry.newFilter("/post").setNext(statusFilter);
		telemetry.newFilter("/post/{name}").setNext(statusFilter);
		telemetry.newFilter("/query/{name}").setNext(statusFilter);
		telemetry.newFilter("/itemImport").setNext(statusFilter);
		telemetry.newFilter("/stream").setNext(statusFilter);
		statusFilter.setNext(router);
        
		String rootPath;
		try {
			File file = new File(".");
			rootPath = file.getCanonicalPath();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
		if(SystemUtils.IS_OS_WINDOWS) {
			Directory directory = new Directory(getContext(), new Reference("file:\\\\" + rootPath + "\\images"));
			router.attach("/images", directory);
		} else {
			Directory directory = new Directory(getContext(), new Reference("file://" + rootPath + "/images"));
			router.attach("/images", directory);
		}
		String hostUriForClients = serviceHost + (omitPort ? "" : ":" + servicePort);
		final String target = hostUriForClients + "/home";
		final Redirector redirector = new Redirector(getContext(), target, Redirector.MODE_CLIENT_TEMPORARY);
		router.attach("/", redirector);

		return router;
	}
}

from applicationinsights-java.

jeanbisutti avatar jeanbisutti commented on May 25, 2024

Hi @avdhut1990

In the Restlet examples I can see that the result of telemetry.newFilter is returned (see this example and this example). Could you try in this way?

from applicationinsights-java.

avdhut1990 avatar avdhut1990 commented on May 25, 2024

Hi @jeanbisutti ,

Following code worked:

private synchronized void attachRoutes(RestletTelemetry telemetry, Router router, String path,
										   Class<? extends ServerResource> targetClass) {
		Filter routeTelemetryFilter = telemetry.newFilter(path);
		StatusFilter statusFilter = new StatusFilter(component.getContext(), new StatusService());
		statusFilter.setNext(targetClass);
		routeTelemetryFilter.setNext(statusFilter);
		router.attach(path, routeTelemetryFilter);
	}

@Override
	public synchronized Restlet createInboundRoot() {
		final Router router = new Router(getContext());
		RestletTelemetry telemetry = RestletTelemetry.builder(GlobalOpenTelemetry.get()).build();

		attachRoutes(telemetry, router, "/query", streamResults ? StreamingQueryResource.class : QueryResource.class);
		attachRoutes(telemetry, router, "/report", ReportResource.class);
		attachRoutes(telemetry, router, "/home", HomeResource.class);
		attachRoutes(telemetry, router, "/systemInfo", SystemInfoResource.class);
		attachRoutes(telemetry, router, "/post", PostResource.class);
		attachRoutes(telemetry, router, "/post/{name}", PostResource.class);
		attachRoutes(telemetry, router, "/query/{name}", streamResults ? StreamingPostPageQueryResource.class : PostPageQueryResource.class);
		attachRoutes(telemetry, router, "/itemImport", ItemImportResource.class);
		attachRoutes(telemetry, router, "/stream", StreamResource.class);

		String rootPath;
		try {
			File file = new File(".");
			rootPath = file.getCanonicalPath();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
		if(SystemUtils.IS_OS_WINDOWS) {
			Directory directory = new Directory(getContext(), new Reference("file:\\\\" + rootPath + "\\images"));
			router.attach("/images", directory);
		} else {
			Directory directory = new Directory(getContext(), new Reference("file://" + rootPath + "/images"));
			router.attach("/images", directory);
		}
		String hostUriForClients = serviceHost + (omitPort ? "" : ":" + servicePort);
		final String target = hostUriForClients + "/home";
		final Redirector redirector = new Redirector(getContext(), target, Redirector.MODE_CLIENT_TEMPORARY);
		router.attach("/", redirector);

		return router;
	}

Is it possible to capture the request and response body as well within restlet and app insights?

Thanks.

from applicationinsights-java.

jeanbisutti avatar jeanbisutti commented on May 25, 2024

@avdhut1990 Could you please create a PR here for a minimal reproducible example with explanations on how to run the example?

from applicationinsights-java.

jeanbisutti avatar jeanbisutti commented on May 25, 2024

@avdhut1990
Perhaps you mean that you can see the HTTP requests on Application Insights UI but not their body?

from applicationinsights-java.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.