Duration : 30 mins
Persona : API Team
Apigee provides extension policies to allow you to quickly leverage third party cloud services as part of the API proxies you deploy. It is common for API teams to need logging and monitoring to be able to diagnose and troubleshoot issues which may arise in production for the client applications they support through the platform. In this lab we’ll explore using the Google Cloud Stackdriver Logging Extension to write log data to Stackdriver Logging.
Apigee provides Extensions policies to integrate external resources into API proxies. For example, you can integrate Google Cloud Platform services such as Google Stackdriver Logging. At run time, an API proxy uses the extension to exchange requests and responses with the external resource. The Extension configuration is a one time setup after which you can leverage the extension policy in your API proxies to perform actions that the third party service can provide. In this lab, we will write log message to Google Stackdriver Logging using the extension policy provided.
You must have a service account key associated with your project to do the next steps in this lab.
To create a service account for this lab:
Click Create. This will download a service account file to your local machine. We will use the contents to setup our Google Stackdriver Logging Extension.
This completes the service account setup.
In Apigee Edge console, go to Admin → Extensions and click the +Add Extension button in the top right corner of the screen.
Search for Stackdriver in the New Extension creation wizard and click Google Stackdriver Logging
Click Create when finished.
Under Environment Configurations click on the test environment to configure it’s properties.
In the Configurations: test modal box that appears, set the following properties:
Click Save.
Go to Develop → API Proxies and click the +Proxy button in the top right corner of the page.
Select Reverse Proxy then click Next.
Enter the following for the proxy details:
Click Next.
In the Security step, click Pass Through then click the Next button.
In the Virtual Hosts step, un-select default. Click Next.
In the last step click, Build and Deploy. Once created, click the link at the bottom of the screen to be taken to the proxy.
Go to the Develop tab of the proxy editor.
Click the +Step button of the proxy endpoint PreFlow Response.
Click Add.
```
Switch over to the Trace tab of the proxy editor and click Start Trace Session.
Press send a few times to send log data to our newly created Global log entry apigee-log-data. We will confirm that logs were sent to Stackdriver Logging in our GCP project in the next steps. Click the elements in the trace pointed out in the image below to confirm you are seeing the same data that is returned from our products API to Stackdriver Logging.
This concludes the hands on portion of this lab. If you experience any issues viewing log data please ask your instructor for assistance.
If you like to learn by watching, here is a short video on leveraging extension policies in API proxies - ????
Now that you understand how to log data with the Google Stackdriver Logging extension. See if you can configure and deploy other Extensions available from the list of supported Extensions page.
That completes this hands-on lesson. In this lab you learned how to create an Extension Policy that leverages Google Stackdriver Logging and send data to a Google Cloud Platform project without the need to understand the underlying REST APIs that Google Cloud exposes for interacting with its services or implementing complex authentication logic.
Useful Apigee documentation links on Policy Composition -
Extensions Overview - https://docs.apigee.com/api-platform/extensions/extensions-overview
Extensions Reference - https://docs.apigee.com/api-platform/reference/extensions/reference-overview-extensions
How did you like this lab? Rate here.
Now go to Module-4