generated from newrelic-experimental/java-instrumentation-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
912 additions
and
274 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
273 changes: 245 additions & 28 deletions
273
...pters-ejb/src/main/java/com/newrelic/instrumentation/labs/sap/adapters/ejb/DataUtils.java
Large diffs are not rendered by default.
Oops, something went wrong.
148 changes: 107 additions & 41 deletions
148
...jb/src/main/java/com/newrelic/instrumentation/labs/sap/adapters/ejb/EJBAdapterLogger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,136 @@ | ||
package com.newrelic.instrumentation.labs.sap.adapters.ejb; | ||
|
||
import java.io.IOException; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileOutputStream; | ||
import java.io.PrintWriter; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
import com.newrelic.api.agent.NewRelic; | ||
|
||
public class EJBAdapterLogger { | ||
|
||
public static boolean initialized = false; | ||
private static Logger LOGGER; | ||
private static Logger LOGGER2; | ||
private static PrintWriter LOGGER; | ||
private static PrintWriter LOGGER2; | ||
private static PrintWriter LOGGER3; | ||
private static AdapterLoggingConfig config; | ||
private static NRLabsHandler ctx_handler; | ||
private static NRLabsHandler supp_handler; | ||
private static final Set<String> principalAttributesList; | ||
private static final Set<String> loggedAttributes = new HashSet<String>(); | ||
private static final Set<String> loggedSupplemental = new HashSet<String>(); | ||
private static final Set<String> loggedPrincipal = new HashSet<String>(); | ||
|
||
protected static final String CONTEXT_LOGFILENAME = "context-data-attributes-ejb.log"; | ||
protected static final String DATA_LOGFILENAME = "moduledata-supplemental-attributes-ejb.log"; | ||
protected static final String DATA_PRINCIPAL_LOGFILENAME = "moduledata-principal-attributes-ejb.log"; | ||
|
||
static { | ||
principalAttributesList = new HashSet<String>(); | ||
principalAttributesList.add("Message-Action"); | ||
principalAttributesList.add("Message-CorrelationId"); | ||
principalAttributesList.add("Message-FromParty"); | ||
principalAttributesList.add("Message-FromService"); | ||
principalAttributesList.add("Message-Id"); | ||
principalAttributesList.add("Message-Protocol"); | ||
principalAttributesList.add("Message-SequenceId"); | ||
principalAttributesList.add("Message-ToParty"); | ||
principalAttributesList.add("Message-ToService"); | ||
principalAttributesList.add("Message-AttachmentCount"); | ||
principalAttributesList.add("Message-AttachmentNames"); | ||
principalAttributesList.add("Message-ErrorInfo"); | ||
principalAttributesList.add("Message-Description"); | ||
principalAttributesList.add("Message-RefToMessageId"); | ||
principalAttributesList.add("Message-TimeReceived"); | ||
principalAttributesList.add("Message-TimeSent"); | ||
|
||
public static void initialize() { | ||
config = new AdapterLoggingConfig(); | ||
String logFileName = config.getContextLog(); | ||
|
||
try { | ||
ctx_handler = new NRLabsHandler(logFileName); | ||
} catch (IOException e) { | ||
NewRelic.getAgent().getLogger().log(Level.FINE, e, "Failed to create Attribute log file at {0}", logFileName); | ||
} | ||
|
||
if(LOGGER == null) { | ||
LOGGER = Logger.getLogger("AdaptersEJBLog"); | ||
} | ||
|
||
if(LOGGER != null && ctx_handler != null) { | ||
LOGGER.addHandler(ctx_handler); | ||
} | ||
|
||
logFileName = config.getSupplementalLog(); | ||
principalAttributesList.add("TransportableMessage-MessagePriority"); | ||
principalAttributesList.add("TransportableMessage-Retries"); | ||
principalAttributesList.add("TransportableMessage-SequenceNumber"); | ||
principalAttributesList.add("TransportableMessage-PersistUntil"); | ||
principalAttributesList.add("TransportableMessage-ValidUntil"); | ||
principalAttributesList.add("TransportableMessage-VersionNumber"); | ||
principalAttributesList.add("TransportableMessage-ParentId"); | ||
|
||
principalAttributesList.add("MessageKey-Direction"); | ||
principalAttributesList.add("MessageKey-ID"); | ||
|
||
try { | ||
supp_handler = new NRLabsHandler(logFileName); | ||
} catch (IOException e) { | ||
NewRelic.getAgent().getLogger().log(Level.FINE, e, "Failed to create supplemental attribute log file at {0}", logFileName); | ||
} | ||
principalAttributesList.add("Endpoint-Address"); | ||
principalAttributesList.add("Endpoint-Transport"); | ||
|
||
principalAttributesList.add("Payload-Name"); | ||
principalAttributesList.add("Payload-Description"); | ||
principalAttributesList.add("Payload-ContentType"); | ||
principalAttributesList.add("Payload-AttributeNames"); | ||
|
||
} | ||
|
||
public static void initialize() { | ||
|
||
if(LOGGER2 == null) { | ||
LOGGER2 = Logger.getLogger("AdaptersSupplementalLog"); | ||
if(initialized) return; | ||
config = new AdapterLoggingConfig(); | ||
String logFileName = config.getContextLog(); | ||
try { | ||
FileOutputStream fos = new FileOutputStream(logFileName, false); | ||
LOGGER = new PrintWriter(fos); | ||
} catch (FileNotFoundException e) { | ||
NewRelic.getAgent().getLogger().log(Level.FINE, e, "Failed to find file {0} for logging", logFileName); | ||
} | ||
|
||
logFileName = config.getSupplementalLog(); | ||
try { | ||
FileOutputStream fos2 = new FileOutputStream(logFileName, false); | ||
LOGGER2 = new PrintWriter(fos2); | ||
} catch (FileNotFoundException e) { | ||
NewRelic.getAgent().getLogger().log(Level.FINE, e, "Failed to find file {0} for logging", logFileName); | ||
} | ||
|
||
logFileName = config.getPrincipaladapterLog(); | ||
try { | ||
FileOutputStream fos3 = new FileOutputStream(logFileName, false); | ||
LOGGER3 = new PrintWriter(fos3); | ||
} catch (FileNotFoundException e) { | ||
NewRelic.getAgent().getLogger().log(Level.FINE, e, "Failed to find file {0} for logging", logFileName); | ||
} | ||
initialized = true; | ||
} | ||
|
||
public static void logNewAttribute(String attribute) { | ||
if(!initialized) { | ||
initialize(); | ||
} | ||
|
||
if(LOGGER2 != null && supp_handler != null) { | ||
LOGGER2.addHandler(supp_handler); | ||
if(!loggedAttributes.contains(attribute)) { | ||
loggedAttributes.add(attribute); | ||
NewRelic.getAgent().getLogger().log(Level.FINE, "Adding attribute {0} to loggedAttributes, size is now {1}", attribute, loggedAttributes.size()); | ||
LOGGER.println(attribute); | ||
LOGGER.flush(); | ||
} | ||
initialized = true; | ||
} | ||
|
||
public static void logNewAttribute(String attribute) { | ||
public static void logNewSupplementalAttribute(String attribute) { | ||
if(!initialized) { | ||
initialize(); | ||
} | ||
LOGGER.info(attribute); | ||
if(!loggedSupplemental.contains(attribute)) { | ||
loggedSupplemental.add(attribute); | ||
|
||
NewRelic.getAgent().getLogger().log(Level.FINE, "Adding attribute {0} to loggedSupplemental, size is now {1}", attribute, loggedSupplemental.size()); | ||
LOGGER2.println(attribute); | ||
LOGGER2.flush(); | ||
} | ||
} | ||
|
||
public static void logNewSupplementalAttribute(String attribute) { | ||
public static void logNewPrincipalAttribute(String type, String attribute) { | ||
if(!initialized) { | ||
initialize(); | ||
} | ||
LOGGER2.info(attribute); | ||
String attrName = type+": " +attribute; | ||
|
||
if(!loggedPrincipal.contains(attrName)) { | ||
loggedPrincipal.add(attrName); | ||
NewRelic.getAgent().getLogger().log(Level.FINE, "Adding attrName {0} to loggedPrincipal, size is now {1}", attrName, loggedPrincipal.size()); | ||
LOGGER3.println(type+": " +attribute); | ||
LOGGER3.flush(); | ||
} | ||
} | ||
} |
13 changes: 0 additions & 13 deletions
13
...ejb/src/main/java/com/newrelic/instrumentation/labs/sap/adapters/ejb/NRLabsFormatter.java
This file was deleted.
Oops, something went wrong.
44 changes: 0 additions & 44 deletions
44
...s-ejb/src/main/java/com/newrelic/instrumentation/labs/sap/adapters/ejb/NRLabsHandler.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.