Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ public class ComponentsDefine {

public static final OfficialComponent RESTEASY = new OfficialComponent(62, "RESTEasy");

public static final OfficialComponent SOLRJ = new OfficialComponent(63, "solrj");

private static ComponentsDefine INSTANCE = new ComponentsDefine();

private String[] components;
Expand Down Expand Up @@ -179,6 +181,7 @@ public ComponentsDefine() {
addComponent(VERTX);
addComponent(SPRING_CLOUD_GATEWAY);
addComponent(RESTEASY);
addComponent(SOLRJ);
}

private void addComponent(OfficialComponent component) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,5 +193,18 @@ public static class Toolkit {
*/
public static boolean USE_QUALIFIED_NAME_AS_OPERATION_NAME = false;
}

public static class SolrJ {
/**
* If true, trace all the query parameters(include deleteByIds and deleteByQuery) in Solr query request, default is false.
*/
public static boolean TRACE_STATEMENT = false;

/**
* If true, trace all the operation parameters in Solr request, default is false.
*/
public static boolean TRACE_OPS_PARAMS = false;
}

}
}
1 change: 1 addition & 0 deletions apm-sniffer/apm-sdk-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<module>dubbo-2.7.x-conflict-patch</module>
<module>vertx-plugins</module>
<module>resteasy-plugin</module>
<module>solrj-7.x-plugin</module>
</modules>
<packaging>pom</packaging>

Expand Down
47 changes: 47 additions & 0 deletions apm-sniffer/apm-sdk-plugin/solrj-7.x-plugin/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
~ this work for additional information regarding copyright ownership.
~ The ASF licenses this file to You under the Apache License, Version 2.0
~ (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>apm-sdk-plugin</artifactId>
<groupId>org.apache.skywalking</groupId>
<version>6.2.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>apm-solrj-7.x-plugin</artifactId>
<packaging>jar</packaging>

<name>solrj-7.x-plugin</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<solr-solrj.version>7.7.1</solr-solrj.version>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>${solr-solrj.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.plugin.solrj;

import org.apache.http.client.methods.HttpRequestBase;
import org.apache.skywalking.apm.agent.core.context.CarrierItem;
import org.apache.skywalking.apm.agent.core.context.ContextCarrier;
import org.apache.skywalking.apm.agent.core.context.ContextManager;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;

import java.lang.reflect.Method;

public class SolrConnectorInterceptor implements InstanceMethodsAroundInterceptor {

@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
MethodInterceptResult result) throws Throwable {
if (ContextManager.isActive()) {
HttpRequestBase request = (HttpRequestBase) allArguments[0];

ContextCarrier carrier = new ContextCarrier();
ContextManager.inject(carrier);

CarrierItem items = carrier.items();
while (items.hasNext()) {
items = items.next();
request.setHeader(items.getHeadKey(), items.getHeadValue());
}
}
}

@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
Object ret) throws Throwable {
return ret;
}

@Override
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Throwable t) {
if (ContextManager.isActive()) {
ContextManager.activeSpan().errorOccurred().log(t);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.plugin.solrj.commons;

public class SolrjInstance {
private String collection = "Unknown";
private String remotePeer = "Unknown";

public String getCollection() {
return collection;
}

public void setCollection(String collection) {
this.collection = collection;
}

public String getRemotePeer() {
return remotePeer;
}

public void setRemotePeer(String remotePeer) {
this.remotePeer = remotePeer;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.plugin.solrj.commons;

import org.apache.skywalking.apm.agent.core.context.tag.StringTag;

public class SolrjTags {
public static StringTag TAG_QT = new StringTag("qt");
public static StringTag TAG_COLLECTION = new StringTag("collection");

public static StringTag TAG_Q_TIME = new StringTag("QTime");
public static StringTag TAG_STATUS = new StringTag("status");

public static StringTag TAG_START = new StringTag("start");
public static StringTag TAG_SORT_BY = new StringTag("sort");
public static StringTag TAG_NUM_FOUND = new StringTag("numFound");

public static StringTag TAG_SOFT_COMMIT = new StringTag("softCommit");
public static StringTag TAG_COMMIT_WITHIN = new StringTag("commitWithin");
public static StringTag TAG_MAX_OPTIMIZE_SEGMENTS = new StringTag("maxOptimizeSegs");

public static StringTag TAG_DOCS_SIZE = new StringTag("docsSize");
public static StringTag TAG_DELETE_VALUE = new StringTag("delete.by");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.skywalking.apm.plugin.solrj.define;

import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
import net.bytebuddy.matcher.ElementMatchers;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint;
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch;
import org.apache.skywalking.apm.agent.core.plugin.match.NameMatch;

public class SolrClientInstrumentation extends ClassInstanceMethodsEnhancePluginDefine {

@Override
protected ConstructorInterceptPoint[] getConstructorsInterceptPoints() {
return new ConstructorInterceptPoint[]{
new ConstructorInterceptPoint() {

@Override
public String getConstructorInterceptor() {
return "org.apache.skywalking.apm.plugin.solrj.SolrClientInterceptor";
}

@Override
public ElementMatcher<MethodDescription> getConstructorMatcher() {
return ElementMatchers.any();
}
}
};
}

@Override
protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
return new InstanceMethodsInterceptPoint[]{
new InstanceMethodsInterceptPoint() {
@Override
public boolean isOverrideArgs() {
return false;
}

@Override
public ElementMatcher<MethodDescription> getMethodsMatcher() {
return ElementMatchers.named("request").and(ElementMatchers.takesArguments(3));
}

@Override
public String getMethodsInterceptor() {
return "org.apache.skywalking.apm.plugin.solrj.SolrClientInterceptor";
}
},
new InstanceMethodsInterceptPoint() {
@Override
public boolean isOverrideArgs() {
return false;
}

@Override
public ElementMatcher<MethodDescription> getMethodsMatcher() {
return ElementMatchers.named("executeMethod");
}

@Override
public String getMethodsInterceptor() {
return "org.apache.skywalking.apm.plugin.solrj.SolrConnectorInterceptor";
}
}
};
}

@Override
protected ClassMatch enhanceClass() {
return NameMatch.byName("org.apache.solr.client.solrj.impl.HttpSolrClient");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

solrj-7.x=org.apache.skywalking.apm.plugin.solrj.define.SolrClientInstrumentation
Loading